我一直在尋找反應重構庫,並試圖在這裏把握區別,結果是一樣的,試圖閱讀文檔,但變得更加困惑,爲什麼有兩種方法可以做同樣的事情?WithProps vs withHandlers
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)
}))
)