react-itertools
Advanced tools
Comparing version 0.0.2 to 0.0.3
{ | ||
"name": "react-itertools", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "A suite of tools for manipulating React children", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -34,2 +34,52 @@ # React Itertools | ||
## Example | ||
[Try the CodeSandbox Example!](https://codesandbox.io/s/flamboyant-nightingale-yvirv?file=/src/App.js) | ||
```jsx | ||
import { map } from "react-itertools"; | ||
import { isValidElement } from "react"; | ||
const MapExample = ({ children }) => { | ||
const fn = (el) => { | ||
return ( | ||
<div | ||
style={{ | ||
border: "1px solid black", | ||
padding: "10px", | ||
backgroundColor: "blanchedalmond", | ||
}} | ||
> | ||
{isValidElement(el) && el.props.children} | ||
</div> | ||
); | ||
}; | ||
return <>{map(children, fn)}</>; | ||
}; | ||
export default function App() { | ||
return ( | ||
<> | ||
<p> | ||
`map` recursively iterates through all `children` and returns the | ||
transformed result of applying `fn` to each child. | ||
</p> | ||
<p>Recurses depth first, post-order.</p> | ||
<MapExample> | ||
<div> | ||
<div> | ||
<div /> | ||
<div /> | ||
</div> | ||
<div> | ||
<div /> | ||
<div /> | ||
</div> | ||
</div> | ||
</MapExample> | ||
</> | ||
); | ||
} | ||
``` | ||
## Highlights | ||
@@ -50,1 +100,5 @@ | ||
See the project's [MIT License](https://github.com/tatethurston/react-itertools/blob/master/LICENSE). | ||
``` | ||
``` |
16753
103