Render Props
是指一种在 React 组件之间使用一个值为函数的 prop 在 React 组件间共享代码的简单技术。
import Cat from 'components/cat'
class DataProvider extends React.Component {
constructor(props) {
super(props);
this.state = { target: 'Zac' };
}
render() {
return (
<div>
{this.props.render(this.state)}
</div>
)
}
}
<DataProvider render={data => (
<Cat target={data.target} />
)}/>Last updated