N
N
Ninja Mate2017-07-26 21:50:31
JavaScript
Ninja Mate, 2017-07-26 21:50:31

What is the best way to return the states to their original state in my case (redux)?

There is an application for accounting and monitoring the work of employees. When choosing a task, a form opens (350-1000 fields), all this expands and is displayed gradually when we select certain actions and fill in the fields.
If I need to return some of the states to their original state for a separate state branch, then how can I do this better and how can I properly organize the states themselves?
An example of an event fork

<select
          className={"form-control"}
          name={field}
          value={value}
          onChange={e=>{
//onChange(value, name) это redux action задающий стейты
              onChange(e.target.value, e.target.name)
              if(e.target.value==='F2F') onChange(true, 'openF2F') //Вот тут как сделать через if /else или 
//onCollapse('openF2F', true) думаю можно сделать action в котором будут происходить изменения стейтов
//Хорошая ли это идея?
              else { //Можно разбить по группам
                  onCollapse('openF2F', false)
                  onCollapse('openWhereOther', false)
                  ...//Можно по одному, так нагляднее и быстрее, но кода больше на одной странице 
                  onChange('','services_ff')
                  onChange('','services_ff_other')
                  ...
              }
          }}
      >
          <option key={99} value=''>Select</option>
          {howList.map((item, i)=>{return <option key={i} value={item}>{item}</option>})}

      </select>

Does it make sense to split the straights into branches or is it superfluous
const initialState = {
// Ветки развития событий
    facilities: ['Select'],
    showModal: false,
    modalBodyContainer: '',
    openF2F: false,
    openWhereOther: false,
    openRelPat: false,
    openECFOther: false,
    openMainOptions: false,
// Сами стейты 350-1000 штук на форму
    loc: '',
    engagement_services: '',
    services_ff: '',
    services_ff_other: '',
    ps_target: '',
    relationship: '',
    ps_relationship_other: '',
...
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Hazrat Hajikerimov, 2017-07-26
@victorzadorozhnyy

The most correct approach is to describe several asynchronous actions (redux-thunk) to clean up certain state data

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question