Sign in
Log inSign up

Question: Preparing data in Render vs getDerivedStateFromProps

Nathan Horrigan's photo
Nathan Horrigan
·Jul 25, 2018

Hi, I'm looking for the best lifecycle method approach for my situation. I have some data provided via props from redux, this data needs to be run through a prepareData function before I can loop over it.

Is the best approach to call the function in getDerivedStateFromProps and store the final data in state or call the function in the render method like so:

<SectionList
    sections={this.prepareData(this.props.data)} />
Hassle-free blogging platform that developers and teams love.
  • Docs by Hashnode
    New
  • Blogs
  • AI Markdown Editor
  • GraphQL APIs
  • Open source Starter-kit

© Hashnode 2024 — LinearBytes Inc.

Privacy PolicyTermsCode of Conduct