This.props 'missing' Method Using Conect From React-redux
Solution 1:
I'm not sure what exactly you are missing but running your code does print the props and shows the action as expected:
Edit
I think i know why you are not seeing the function when you log it.
You are looking at the console of the code sandbox application, which probably is doing a serialization of the props object.
The problem is that functions are not serialize-able.
From the docs:
Functions are not a valid JSON data type so they will not work. However, they can be displayed if first converted to a string
You can run the code below to see how JSON.stringify for instance, is not serializing the function inside the object.
const obj = {
someKey: 'some Value',
someFunc: function() {}
};
console.log(JSON.stringify(obj));FYI: You don't need to create an inline arrow function to pass it down to the onClick event, you can just pass the reference via the props.
So change this:
<buttononClick={() => this.props.approveItem()}>Approve </button>To this:
<buttononClick={this.props.approveItem}>Approve </button>Solution 2:
approveItem function is available in this.props
this.props.approveItem()
this.props is always an object, never be a function, Just think if we need to have multiple functions in props, we can have multiple function only if this.props is object. Not possible if this.props is itself as function.
Seeing methods in this.props object. Please look into console - https://codesandbox.io/s/xpy0lmolr4

Post a Comment for "This.props 'missing' Method Using Conect From React-redux"