Closed GHEMID-Mohamed closed 7 years ago
There isn't a way to directly get at props
from a computed property. Due to freactal
's hierarchical nature, it wouldn't be possible to know which prop is being referenced, since the state can come from anywhere higher in the component tree.
However, you can use the pattern of setting initial state from props
that are provided. initialState
of the Child
component accepts props
as its argument. So in your example, you would do something like:
const Child = provideState({
initialState: ({ id }) => ({ id, name: "Zaki" }), // <-- CHANGE MADE ON THIS LINE
computed: {
childWithId: ({ id, name }) => `${state.name} ${id}`
}
})(injectState(({ state }) => (
<div>
{state.childWithId}
</div>
));
I hope that helps!
Yes Thank you, that resovle the problem :)
Hello :1st_place_medal:
I can't access to props of the component in computed values
Do you have any idea of how this can be done ?