How to compose redux reducers with dependent state

后端 未结 4 1835
别跟我提以往
别跟我提以往 2021-02-04 08:47

I am working on a React/Redux application that allows for \"widgets\" to be added to a page and manipulated in 2D space. It is a requirement that multiple widgets can be selecte

4条回答
  •  面向向阳花
    2021-02-04 09:32

    You can try to use:

    redux-named-reducers

    Which allows you to get state anywhere in your code like so:

    const localState1 = getState(reducerA.state1)
    const localState2 = getState(reducerB.state2)
    

    Or to assign external dependent state to your reducers like so:

    reducerA.extState1 = reducerB.state1

    Then access it like so:

    getState(reduerA.extState1)

提交回复
热议问题