api react code example
Example 1: React Children map example
export default class SomeComponent extends React.Component {
render() {
const childrenWithWrapperDiv = React.Children.map(this.props.children, child => {
return (
<div className="some-component-special-class">{child}</div>
);
});
return (
<div className="some-component">
<p>This component has {React.Children.count(this.props.children)} children.</p>
{childrenWithWrapperDiv}
</div>
);
}
}
Example 2: React get method
componentWillMount(){
fetch('/getcurrencylist',
{
method: "get",
dataType: 'json',
})
.then((res) => res.json())
.then((data) => {
var currencyList = [];
for(var i=0; i< data.length; i++){
var currency = data[i];
currencyList.push(currency);
}
console.log(currencyList);
this.setState({currencyList})
console.log(this.state.currencyList);
})
.catch(err => console.log(err))
}