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

179
Views
¿Se puede usar router.push desde Redux thunk? ¿Es una buena práctica?

Tengo este elemento de anclaje:

 <a className="btn btn-sm btn-circle" href={`https://www.facebook.com/sharer/sharer.php?u=${ process.env.NEXT_PUBLIC_ENVIRONMENT == "prod" ? "https://tikex.com" : "https://tikex-staging.com" }/share/${organizationSlug}/${postId}&quote=${postSurveySchemaDTO?.caption}`} onClick={(e) => { dispatch( createShare({ tempUserId: "e3445c3b-5513-4ede-8229-d258ed4418ae", postId, }) ); }} > Megosztom </a>

Probé muchas veces, tal vez solo una vez, pero parece que onclick y networking no se activaron en ese caso, 99% bien. ¿Es mejor activar la navegación también desde onClick después de realizar la red?

¿Puedo activar router.push() desde reducer / thunk ?

¿Como esto?

 export const createShare = createAsyncThunk( `${namespace}/createShare`, async (props: any, { dispatch }) => { const { data } = await axios({ method: 'post', url: 'share', data: props, headers: { crossDomain: true }, }).then((res) => { router.push(`http://...`) return res }) return data } )
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Parece que tienes una condición de carrera.

  1. el <a> está tratando de navegar el navegador lejos del href
  2. onClick tiene un disparador de dispatch(createShare(...))

Sugeriría evitar el evento <a> predeterminado y coreografiar manualmente los dos eventos separados:

 onClick(e => { e.preventDefault() // stop the browser from trying to navigate away dispatch( createShare({ ... thenNavigateTo: e.target.href // or whatever }) ) }

Si necesita un router para navegar, puede pasar un thunk a la acción enviada:

 onClick(e => { e.preventDefault() // stop the browser from trying to navigate away dispatch( createShare({ ... andThen: _ => router.push(e.target.href) // or whatever }) ) }
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!