Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

216
Vistas
React Component is not rerendered after a prop change

Today in SorninHeadachePost we have a new React render that doesn't occur.

I'll try to explain as best as I can and give maximum informations (do not hesitate if you think something is missing).

SO !

I have a React component named Navigation that should re-render once it's props change.

    //[...]
    const [availableViews, setAvailableViews] = useState(props.availableViews)
    const [userViews, setUserViews] = useState(props.userViews)
    const [_, forceUpdate] = useReducer((x) => x + 1, 0);

    useEffect(() => {
        setAvailableViews(props.availableViews)
    }, [props.availableViews])

    useEffect(() => {
        setUserViews(props.userViews)
        console.log("the log")
        forceUpdate()
    }, [props.userViews])

    return (
        <div className="navigation-root">
                <div className="navigation-title">
                    <img src={dashboardSVG} alt="Dashboard"/>
                    <span className="navigation-titleSpan">DASHBOARD</span>
                </div>
                <div className="navigation-tabContainer">
                    {
                        props.dataInitialized && availableViews.length > 0
                            ?
                            availableViews.map((d:ViewObject, key:any) => {
                                if (d.viewName.startsWith("Default ")) {
                                    let views: ViewObject[] = []
                                    for (let i = 0; i<userViews.length;i++) {
   //[...]

In this code snippet that represent the React component Navigation, the prop userViews changes on a user action, the log (the log) is being thrown on this action, so the prop is updated.

But nothing change....

May it be because the logic that use the state userViews is wrapped into a .map callback. (If it's because of this, how can it be rerendered)

As you can see I tried the hack of the reducer to forceupdate. Nothing changes either.

At this point I'm looking for a full rerender of this component so it updates all child components.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda