You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 2, 2024. It is now read-only.
*__[List](https://csvenke.github.io/react-semantic-render/#/List)__: Renders content from an array of data.
44
-
*__[Show](https://csvenke.github.io/react-semantic-render/#/Show)__: Renders content when specified condition is true.
45
-
*__[Switch](https://csvenke.github.io/react-semantic-render/#/Switch)__: Renders content from first case that matches, else default if it exists.
46
-
*__Tiny bundle size__
47
-
*__100% test coverage__
48
-
*__Production ready__
49
-
*__Blazing fast__
50
-
*__TypeScript type definitions__
42
+
-**Growing list of semantic helper components and hocs**
43
+
-**[List](https://csvenke.github.io/react-semantic-render/#!/List)**: Renders content from an array of data.
44
+
-**[Switch](https://csvenke.github.io/react-semantic-render/#!/Switch)**: Renders content from first case that matches, else default if it exists.
45
+
-**[Show](https://csvenke.github.io/react-semantic-render/#!/Show)**: Renders content when specified condition is true.
46
+
-**[ShowIfElse](https://csvenke.github.io/react-semantic-render/#!/ShowIfElse)**: Renders content when condition is true, else renders something else.
47
+
-**[Hideable](https://csvenke.github.io/react-semantic-render/#!/Hideable)**: Higher order component that injects 'hideComponent' prop into specified component.
import { Show, List } from'react-semantic-render';
73
+
importReactfrom'react';
74
+
importShowfrom'react-semantic-render/Show';
75
+
76
+
constApp= ({ showButton }) => (
77
+
<Show when={showButton}>
78
+
<button>Click me!</button>
79
+
</Show>
80
+
);
70
81
```
71
82
83
+
Render list of names
84
+
72
85
```jsx
73
-
<div>
74
-
<Show when={true}>
75
-
<List
76
-
items={[1, 2, 3, 4, 5]}
77
-
render={data=><div>{data}</div>}
78
-
/>
79
-
</Show>
80
-
</div>
86
+
importReactfrom'react';
87
+
importListfrom'react-semantic-render/List';
88
+
89
+
constApp= () => (
90
+
<ul>
91
+
<List items={['John', 'Jane', 'Bill', 'Pete']}>
92
+
{name=> (
93
+
<li key={name}>
94
+
<span>{name}</span>
95
+
</li>
96
+
)}
97
+
</List>
98
+
</ul>
99
+
);
100
+
```
101
+
102
+
Render message when condition is true, else render something else
103
+
104
+
```jsx
105
+
importReactfrom'react';
106
+
importSwitchfrom'react-semantic-render/Switch';
107
+
108
+
constApp= ({ showMessage }) => (
109
+
<Switch value>
110
+
<Switch.Case value={showMessage}>
111
+
<span>Render me!</span>
112
+
</Switch.Case>
113
+
<Switch.Default>
114
+
<span>Nobody renders better than me!</span>
115
+
</Switch.Default>
116
+
</Switch>
117
+
);
81
118
```
82
119
83
120
## Why
84
121
85
-
In the example above you see two very common use cases where you have to render something when a condition is true and render content from an array of data.
122
+
In the example below you see a component named `UserList` that contains two very common use cases where you have to render something when a condition is true and render content from an array of data.
86
123
This is usually solved with inline arrow functions that are hard to read and easily becomes unmanageable in more complex components.
87
124
88
-
Below you can see how it would look with inline arrow functions.
0 commit comments