RickBrunstedt
RickBrunstedt

Reputation: 2001

how do I pass additional props into a react component through a higher order function

I think it's called higher order function, but I'm not sure.

What I'm trying to accomplish is something kind of similiar to redux to get a better understanding of how it works, and looking for a good way of passing additional props into a component.

Heres my code.. https://jsfiddle.net/ncc8nprc/2/

I have all the props that I want inside the constructor, but not in the rest of the class e.g. render method.

And I get an error that says make sure to pass up the same props that your component's constructor was passed. so I understand this is the wrong way of doing it. :P

But how can I accomplish this?

Thanks!

Upvotes: 0

Views: 290

Answers (1)

Damien Leroux
Damien Leroux

Reputation: 11693

You need to return a valid React Component from your high order component, it means using the jsx syntax and a Uppercase first letter:

    function stateConnector(mapStateToProps) {
        return function(Component) {

            return class Wrap extends Component {
                render() {
                    const combinedProps = { ...this.props, ...AppState};
                    return <Component {...combinedProps}/>;

                }
            }
        };
    }

Here is the working jsfiddle.

Upvotes: 1

Related Questions