是否存在將redux狀態綁定到對象的既定方法?將redux狀態綁定到對象
我想要做這樣的事情:
MyApi.setStore(myReduxStore, 'stateVar')
我已經打了通過各種的get/set操作和存儲的聽衆,但它是一個爛攤子。
MyApi.getState =() => store.dispatch(getAction())
MyApi.setState = (state) => store.dispatch(setAction(state))
let currentState
store.subscribe(() => {
let previousState = currentState
currentState = store.getState().stateVar
if(previousState !== currentState) {
MyApi.stateListener(currentState)
}
})
你想達到什麼目的? Redux狀態已經是對象... – Andrey
我的API做一些異步的東西。我希望它能將它的狀態暴露給redux,所以它可以在各種反應組件中找到。 – Simon
知道每個reducer都返回新狀態,您可以創建將從您的API返回狀態的reducer。 – Andrey