2016-09-02 2 views
0

getting started pageは言う: 私の州のルートにある "form"キーにredux-formをマウントする必要がありますか?

import { createStore, combineReducers } from 'redux' 
import { reducer as formReducer } from 'redux-form' 

const reducers = { 
    // ... your other reducers here ... 
    form: formReducer  // <---- Mounted at 'form' 
} 
const reducer = combineReducers(reducers) 
const store = createStore(reducer) 
しかし reduxForm() documentationは言う:

form : String [required]

the name of your form and the key to where your form's state will be mounted under the redux-form reducer

私はSimple Form exampleを実行しています。私はこのコードを持っている:

var reduxFormReducer = reduxForm({ 
    formKey: 'personal' // a unique identifier for this form 
})(SimpleForm); 

var reducer = combineReducers({ 
    formKey: reduxFormReducer 
}); 

をしかし、それはこのエラーを示しています

Warning: Failed prop type: Required prop form was not specified in Form(SimpleForm) . in Form(SimpleForm) (created by Connect(Form(SimpleForm)))

私はこれを試してみた:

var reduxFormReducer = reduxForm({ 
    form: 'formKey' // a unique identifier for this form 
})(SimpleForm); 

var reducer = combineReducers({ 
    formKey: reduxFormReducer 
}); 

それは、そのエラーが表示されませんが、編集フィールドがあります空で変更することはできません。

答えて

1

私はあなたの減速に逃し、

var reduxFormReducer = reduxForm({ 
    form: 'formKey' // a unique identifier for this form 
})(SimpleForm); 

var reducer = combineReducers({ 
    form: reduxFormReducer // <- change formKey to form here 
}); 

formが参照としてキー名を使用してくださいホープ:http://redux-form.com/6.0.2/docs/GettingStarted.md/

更新:

フォーム減速。あなたのRedux状態に取り付けられているのは、formです。

あなたは絶対にform以外のどこかでそれをマウントする必要がある場合、あなたはredux-form減速をマウントしたReduxの状態のスライスを取得するには、reduxForm()デコレータにgetFormState(state)機能を提供することができます。

+0

が動作しますが、質問は私が*使用する*フォーム*ですか?代わりに* state.fooのようなものを使用したいのですが。 – AlexStack

+0

@AlexStack最新の答えを確認してください。 –

関連する問題