Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to inject into React Component props?

Tags:

reactjs

The only way I know to inject props into a component is through a parent component like so

render() {
  return <Child ...this.someProps />
}

How do I inject more props to the Child component dynamically through a function like so

inject(someProps, Child)

Similar to how redux-react connect(mapStateToProps, mapDispatchToProps)(Child) works

like image 507
manni Avatar asked Oct 31 '22 10:10

manni


1 Answers

Higher-order Components is what you are looking for: https://gist.github.com/sebmarkbage/ef0bf1f338a7182b6775

At the end of the day you'll be wrapping your component with a parent one (connect is in fact a component).

like image 157
Raspo Avatar answered Nov 15 '22 05:11

Raspo