Conditionals
1 | return ( |
Javasript way:
1 | render() { |
Delete and Update elements
1 | // UserOutput.js |
Render Adjacent JSX Elements
With array
1
2
3
4
5
6
7
8
9class Person extends Component {
render() {
return [
<p key="i1" >Item One</p>,
<p key="i2" > Item Two</p>,
<input key="i3"/>
]
}
}With a wrapping componnet (HOC)
1
2
3
4
5
6// Aux.js
import React from 'react';
const aux = props => props.children; // Return whatever between the <Aux> and <Aux/>
export default aux;
Use HOC in components
1 | // Component.js |
HOC
Higher order components Do not have representations, rather, they wrap other components inside to achieve some functionalities.
Use this component can remove the warpping HTML <div>
, to bettern styling component
1 | // Aux.js |
Customized Higher Order Components
1 | // WithClass.js |
If the HOC has logics (error handling etc), this would be a better approach
1 |
|