Answer the question
In order to leave comments, you need to log in
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>
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
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 questionAsk a Question
731 491 924 answers to any question