我一直在查看 react recompose 库并试图在这里掌握差异,结果是一样的,尝试阅读文档,但更加困惑,为什么有两种方法可以做同样的事情?
const enhance = compose(
withState('counter', 'setCounter', 0),
withHandlers({
increment: props => () => props.setCounter(n => n + 1),
decrement: props => () => props.setCounter(n => n - 1)
})
)
const enhance = compose(
withState('counter', 'setCounter', 0),
withProps(({ setCounter }) => ({
increment: () => setCounter(n => n + 1),
decrement: () => setCounter(n => n - 1)
}))
)