Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

125
Views
Kit de herramientas Redux y acciones contra código repetitivo

mi código es largo y repetitivo. Debería usar la función auxiliar para cortarlo y hacerlo más mantenible y legible. Soy un principiante de React y tengo una pregunta. ¿Debo hacer la mayor parte de esta lógica con funciones auxiliares en un archivo separado con acciones o dentro de un segmento?

componente:

 const FilterItems: React.FC<FuncProps> = (props) => { const dispatch = useDispatch(); const onChangeHandler = (e: React.ChangeEvent<HTMLInputElement>) => { e.preventDefault(); const content = e.target.value; dispatch( recipeAction.setFilterType({ type: props.type, set: e.target.checked, content: content, }) ); }; redux slice: setFilterType(state, action: PayloadAction<FilterType>) { if (action.payload.type === typeOfFiltering.dishType) { const chosenType = action.payload.content; if (action.payload.set) { state.chosenRecipeTypes.push(chosenType); } if (!action.payload.set) { state.chosenRecipeTypes.filter( (recipeType) => recipeType !== chosenType ); } } if (action.payload.type === typeOfFiltering.dishLength) { const chosenType = action.payload.content; if (action.payload.set) { state.chosenRecipeLengths.push(chosenType); } if (!action.payload.set) { state.chosenRecipeLengths.filter( (recipeType) => recipeType !== chosenType ); } } },
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Si necesita alguna funcionalidad en algunos otros componentes, haga algunas funciones auxiliares y reutilícelas en un componente separado. Si lo usa solo en un lugar, entonces no necesita separar...

también intente usar el interruptor en lugar de si con el caso predeterminado en la parte inferior

y para mi se ve mejor si usas destructores en vez de esto

 const chosenType = action.payload.content;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!