Ad

How To Inject Into React Component Props?

- 1 answer

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

Ad

Answer

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).

Ad
source: stackoverflow.com
Ad