davidkpiano / react-redux-form

Create forms easily in React with Redux.
https://davidkpiano.github.io/react-redux-form
MIT License
2.06k stars 252 forks source link

When using with existing reducers, form state has incorrect `initialValue` #1004

Open bstro opened 6 years ago

bstro commented 6 years ago

The Problem

Here's a simplified version of my createStore function:

export default createStore(
  combineReducers({
    entities,
    ...createForms({
      entities
    })
  }),
  applyMiddleware(…)
);

Note above, that I have a reducer called entities. This is state managed by normalizr, but will serve as the initial state for a few forms I need to build. Consider the following <Form /> instance:

<Form model={track('entities.reports[]', { id: props.report.id })}>
  <Control.text model=".biographical_data.name" />
</Form>

This correctly renders the data in a text field. If I change the contents of the text field, the value in my redux store is successfully mutated. However, when I inspect the redux state that is managed by rrf, I notice that the initialValue property for the field I have mutated shows an incorrect value:

screen shot 2017-11-06 at 2 23 23 pm

In my entities state, the value of this name field is never null. Why would it be null here?

This hasn't caused me problems yet, but this seems like a bug. I would expect the initialValue to be equal to the original value of the property that existed in the redux state.

davidkpiano commented 6 years ago

Can you put this in a CodePen/CodeSandbox so I can more easily diagnose the issue? I do not use normalizr.