Z
Z
zlodiak2021-01-04 17:58:58
React
zlodiak, 2021-01-04 17:58:58

How to display new data that came through props?

There is a component that receives data from the store and puts it in props

function Details(props: any) {
  let details: any
  const routeParams: any = useParams();	

  useEffect(() => {
    details = props.victims.find((victim: any) => routeParams.pk == victim.pk)
    console.log(details)
  }, [props.victims])
  
  return(
    <>
      {
        details && Object.keys(details.fields).map((f: string, i: number) => f)
      }
    </>
  )
}

const mapStateToProps = (state: appStateType) => {
  return {
    victims: state.victimsReducer.victims,
  }
}

export default connect(mapStateToProps, {})(Details);


The problem is that it useEffectworks after return. But the data that I need to display is formed in useEffect. Therefore, the browser displays a blank screen (although the console shows that there is data).

Please help displaydetails.fields

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-01-04
@zlodiak

UseEffect is not needed here. Replace it with useMemo or don't use any hooks at all, get the right value right away.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question