user12551649
user12551649

Reputation: 426

How to pass props to component inside function?

When I try to pass props to Component inside the function it always returns "Expected an assignment or function call and instead saw an expression no-unused-expressions".

handleComponent(){
     <Component getid={value} />
}

why is this happening and how to correct it?

Upvotes: 0

Views: 103

Answers (2)

Tony Nguyen
Tony Nguyen

Reputation: 3488

You used handleComponent in render function (or in return if you use functional component), I gues, so handleComponent need to return a piece of JSX code.Your handleComponent don't have return keyword so it return undefined, that's why you get that error. Try the following code:

handleComponent(){
     return <Component getid={value} />
}

Upvotes: 1

Arpit Vyas
Arpit Vyas

Reputation: 2227

you have to call component in return of render in compoennt like this

 render(){
     return(
       <Component getid={value}/>
     )
    }

Upvotes: 1

Related Questions