Traverse through React Component Tree and Transform the Deepest Strings to Anything
npm install react-with-traverseMore detailed examples can be found in tests/
bash
npm
npm install react-with-traverseyarn
yarn add react-with-traverse
`
Usage
This module exposes a single function.
`javascript
// ES6+
import withTraverse from 'react-with-traverse';// ES5
const withTraverse = require('react-with-traverse');
`
$3
#### transform(child : Any, props : Object) : Nodechild : Each of the deepest strings in the component tree (probably , unless you do something like )props : The props for the result componentUse this function to transform
child into anything you want by returning it.Example:
`javascript
const convertToSmileEmoji = (child, props) => {
const {large} = props;
if (child === ':smile:') {
const src = large ? 'smile_large.png' : 'smile.png';
return
;
}
return child;
};
const Smile = withTraverse(convertToSmileEmoji);
Some text
:smile:
`
Result :
`html
Some text

`Test
``bash