How to use a parameter in ReactJS

syez-code

Im pretty new to coding with JS/REACT. Can someone tell me why the parameter "keyword" in the following code isnt working as a parameter? Thank you!


function FillData(keyword) {
    return <div className="App">
                {
                    Data.map( datan => {
                        return(
                            <div className="box">
                            
                                {datan.keyword}
                                
                            </div>
                        )
                    } )
                }
    </div>
}

Tank you very much in advance!

twharmon

Is this what your are looking for?

function FillData(keyword) {
    return <div className="App">
        {Data.map(datan => (
            <div className="box">
                {datan[keyword]}
            </div>
        ))}
    </div>
}

If FillData is to be used as a component, you might need this instead:

function FillData(props) {
    return <div className="App">
        {Data.map(datan => (
            <div className="box">
                {datan[props.keyword]}
            </div>
        ))}
    </div>
}

Then you can use FillData like this:

<div><FillData keyword="foo" /></div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related