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

154
Views
How can I update the props.data from a child component?

I am trying to display a range from an array that is being passed into a child. My current Parent component is as follows:

import data from './data.json'
return ( 
    <Cell symbol={data.symbol} number={data.number} />
)

And that data is being passed into my Child component:

const [updatedSymbols, setUpdatedSymbols] = useState()

useEffect(() => 
    if(props.number === 1 || props.number === 2 || props.number === 3 ){
             setUpdatedSymbols(props.number)
            console.log("updated: " + props.number)
        }
    }, [props.symbol])

return (
    <div class="cell">
        {updatedSymbols}
    </div>
)

QUESTION: If you look at the useEffect, you will notice that within the if-statement, I am selecting the numbers I want and simply passing them into the useState, "setUpdatedSymbols". My problem is that there are too many numbers that I need to select, about 100, how can I push them all into updatedSymbols without using || ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

whatever the numbers list you want to check before you insert into your state you can collectively do this

    const [updatedSymbols, setUpdatedSymbols] = useState()
    const range = (from, to ) => {
       var collection = [];
       for(let i = from; i<=to ; i++) {
         collection.push(i);
       }
    return collection;
   }
    useEffect(() => 
        if(range(1,100).includes(props.number) ){
                 setUpdatedSymbols(props.number)
                console.log("updated: " + props.number)
            }
        }, [props.symbol])
    
    return (
        <div class="cell">
            {updatedSymbols}
        </div>
    )

    // this is magical trick
    // [1,2,3,4,5].includes(props.number); //if props.number happens to be in the array then it i'll give true
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!