javascript - How to pass or create initial value in the fields of FieldArray? -


i want fields have 1 initial value 1 component render. having problem how pass initial value fields array. tried make condition - if fields empty add 1 answer it. believe because of getting warning http://i.imgur.com/fjecjd4.png . idea how fix ? found this, not sure if relevant me or how use https://github.com/erikras/redux-form/issues/2366 .

    import react 'react'; import { field, fieldarray } 'redux-form'; import answer './answer';  const answerstab = props => {   const renderanswers = ({ fields, meta: { error } }) => {     const addanswer = () => {       fields.push();     };     const removeanswer = () => {       if (fields.length === 1) {         return;       }       fields.pop();     };     if (fields.length === 0) {       addanswer();     }     return (       <div>         {fields.map((answer, index) => (           <field             key={`answers[${props.number}].${props.type}[${index}]`}             id={`sf-input-tab${props.tabnumber}-question2`}             type="text"             component={answer}             label={`${index + 1}. answer`}             name={answer}             addanswer={addanswer}             removeanswer={removeanswer}             last={fields.length - 1 === index}           />           ),         )}       </div>     );   };    return (     <fieldset classname="survey-form">       <fieldarray name={`questions[${props.number}].${props.type}`} component={renderanswers} />     </fieldset>); };  answerstab.proptypes = {   number: react.proptypes.number.isrequired,   type: react.proptypes.string.isrequired,   tabnumber: react.proptypes.string.isrequired, };  export default answerstab; 


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -