简体   繁体   中英

Passing multiple values as props

How can I pass query to Story component

   function Story({data}) {
       return (<div></div>)
   }

   function Feedbacks({feedbackdata}) {
        const {query, feedbacks} = feedbackdata;
      
        return (
            <div>
                {feedbacks.length > 0 && feedbacks.map(feedback => <Story key={feedbacks.id} data={feedback}/>)}
            </div>
        )
    }

Just add it as prop?

and make sure that your Story function/class component handles that extra prop

   function Story({data}) {
       return (<div></div>)
   }

   function Feedbacks({feedbackdata}) {
        const {query, feedbacks} = feedbackdata;
      
        return (
            <div>
                {feedbacks.length > 0 && feedbacks.map(feedback => <Story key={feedbacks.id} data={feedback} query={query} />)}
            </div>
        )
    }

You add a prop to Story .

function Story({data, query}) {
  return (<div></div>)
}

Then pass in that prop like:

<Story key={feedbacks.id} data={feedback} query={query} />

See the docs for more info about props. You can add as many as you like!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM