Open monsterooo opened 6 years ago
withhandlers接收一个对象或函数为其接下来的组件创建事件处理函数,每个事件处理函数都接收一个参数,这个参数就是组件的props。
withhandlers
对象
函数
props
withHandlers( handlerCreators: { [handlerName: string]: (props: Object) => Function } | handlerCreatorsFactory: (initialProps) => { [handlerName: string]: (props: Object) => Function } ): HigherOrderComponent
实际调用也就是两种形式
// 1 withHandlers({ handleClick: props => event => { alert(props.title) } })
// 2 withHandlers(() => { return { handleClick: props => event => { console.log('我被点击了', props); }, }; })
const { compose, withHandlers } = Recompose; const ButtonEnhance = compose( withHandlers({ handleClick: props => event => { alert('我被点击了, ' + props.title) } }) )(({ handleClick }) => ( <button onClick={handleClick}>点我~~</button> ))
在codepen在线预览
withHandlers 介绍
withhandlers
接收一个对象
或函数
为其接下来的组件创建事件处理函数,每个事件处理函数都接收一个参数,这个参数就是组件的props
。withHandlers Flow Type
实际调用也就是两种形式
withHandlers 实例
在线DEMO
在codepen在线预览