Skip to content
This repository was archived by the owner on Jun 2, 2024. It is now read-only.

Commit 970a063

Browse files
committed
docs(readme): improve documentation
1 parent 09d875b commit 970a063

File tree

1 file changed

+32
-48
lines changed

1 file changed

+32
-48
lines changed

README.md

Lines changed: 32 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
<img src="https://img.shields.io/npm/v/react-semantic-render.svg" alt="npm package" />
1212
</a>
1313
<a href="https://bundlephobia.com/result?p=react-semantic-render">
14-
<img src="https://img.shields.io/bundlephobia/min/react-semantic-render.svg" alt="bundle size" />
14+
<img src="https://img.shields.io/bundlephobia/minzip/react-semantic-render.svg" alt="minzipped bundle size" />
1515
</a>
1616
<a href="https://travis-ci.com/csvenke/react-semantic-render">
17-
<img src="https://travis-ci.com/csvenke/react-semantic-render.svg?branch=master" alt="build status" />
17+
<img src="https://travis-ci.com/csvenke/react-semantic-render.svg?branch=master" alt="travis ci build status" />
1818
</a>
1919
<a href='https://coveralls.io/github/csvenke/react-semantic-render?branch=master'>
2020
<img src='https://coveralls.io/repos/github/csvenke/react-semantic-render/badge.svg?branch=master&service=github' alt='coverage status' />
@@ -39,7 +39,7 @@
3939

4040
## Key features
4141

42-
- **Growing list of semantic helper components and hocs**
42+
- **Growing list of semantic helper components and hocs!**
4343
- **[List](https://csvenke.github.io/react-semantic-render/#!/List)**: Renders content from an array of data.
4444
- **[Switch](https://csvenke.github.io/react-semantic-render/#!/Switch)**: Renders content from first case that matches, else default if it exists.
4545
- **[Show](https://csvenke.github.io/react-semantic-render/#!/Show)**: Renders content when specified condition is true.
@@ -71,7 +71,7 @@ Render button when condition is true
7171

7272
```jsx
7373
import React from 'react';
74-
import Show from 'react-semantic-render/Show';
74+
import { Show } from 'react-semantic-render';
7575

7676
const App = ({ showButton }) => (
7777
<Show when={showButton}>
@@ -84,7 +84,7 @@ Render list of names
8484

8585
```jsx
8686
import React from 'react';
87-
import List from 'react-semantic-render/List';
87+
import { List } from 'react-semantic-render';
8888

8989
const App = () => (
9090
<ul>
@@ -99,77 +99,61 @@ const App = () => (
9999
);
100100
```
101101

102-
Render message when condition is true, else render something else
102+
Render message when condition is true, else render button
103103

104104
```jsx
105105
import React from 'react';
106-
import Switch from 'react-semantic-render/Switch';
106+
import { Switch } from 'react-semantic-render';
107107

108108
const App = ({ showMessage }) => (
109109
<Switch value>
110110
<Switch.Case value={showMessage}>
111111
<span>Render me!</span>
112112
</Switch.Case>
113113
<Switch.Default>
114-
<span>Nobody renders better than me!</span>
114+
<button>Click me!</button>
115115
</Switch.Default>
116116
</Switch>
117117
);
118118
```
119119

120120
## Why
121121

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.
122+
In the example below 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.
123123
This is usually solved with inline arrow functions that are hard to read and easily becomes unmanageable in more complex components.
124124

125125
```jsx
126-
const UserList = ({ isLoading, results }) => (
127-
<div>
128-
{isLoading && <span>Loading...</span>}
129-
{!isLoading && !results.length && <span>No results found</span>}
130-
{!isLoading &&
131-
results.length > 0 && (
132-
<ul>
133-
{result.map(user => (
134-
<li key={user.id}>
135-
<span>{user.name}</span>
136-
</li>
137-
))}
138-
</ul>
139-
)}
140-
</div>
126+
const App = ({ isLoading, results }) => (
127+
{results.length > 0 ? (
128+
<ul>
129+
{result.map(user => (
130+
<li key={user.id}>
131+
<span>{user.name}</span>
132+
</li>
133+
))}
134+
</ul>
135+
) : null}
141136
);
142137
```
143138

144139
Here you see how the component above could be rewritten with components from `react-semantic-render`.
145-
While it might be abit more verbose, the readability is greatly increased and you immeadiatly see whats going on.
140+
While it is abit more verbose, the readability is greatly increased and you immeadiatly see whats going on.
146141

147142
```jsx
148143
import { List, Switch } from 'react-semantic-render';
149144

150-
const UserList = ({ isLoading, results }) => (
151-
<div>
152-
<Switch value>
153-
<Switch.Case value={isLoading}>
154-
<span>Loading...</span>
155-
</Switch.Case>
156-
<Switch.Case value={!isLoading && !result.length}>
157-
<span>No results found</span>
158-
</Switch.Case>
159-
<Switch.Case value={!isLoading && results.length > 0}>
160-
<ul>
161-
<List
162-
items={results}
163-
render={user => (
164-
<li key={user.id}>
165-
<span>{user.name}</span>
166-
</li>
167-
)}
168-
/>
169-
</ul>
170-
</Switch.Case>
171-
</Switch>
172-
</div>
145+
const App = ({ isLoading, results }) => (
146+
<Show when={results.length > 0}>
147+
<ul>
148+
<List items={results}>
149+
{user => (
150+
<li key={user.id}>
151+
<span>{user.name}</span>
152+
</li>
153+
)}
154+
</List>
155+
</ul>
156+
</Show>
173157
);
174158
```
175159

0 commit comments

Comments
 (0)