Closed shoebmogal closed 8 years ago
You can pass whatever you like into your hooks, including the entire store. Closing the issue for now, please re-open if you're having issues with this.
Hi @markdalgleish, I have a related question. In your example you are passing "params: {id}". I am using redux and would like to pass a state property, in my example "this.props.initinalPath" to the providerHook. But I am getting "this is not defined" because it looks like the store is not available yet. Above you are writing you could pass store data. Do you have an example how this would like?
My Code
function mapStateToProps (state) {
return {
initinalPath: state.sourceRequest.pathname
}
}
@provideHooks({
fetch: ({ dispatch, params: { this.props.initinalPath} }) => dispatch(loadContent(dataFromParams))
})@connect(mapStateToProps, null)
class Home extends React.Component {
Okay, I figured it out myself. Params get set on the server and passed to the component. I was confused not seeing the 'ID' in the server example.
server.js
const locals = {
path: renderProps.location.pathname,
query: renderProps.location.query,
params: renderProps.params,
// Allow lifecycle hooks to dispatch Redux actions:
dispatch
}
Can you post example component hook which refers these locals? I am unable to figure out a way to refer them in hook.
You can pass whatever you like into your hooks, including the entire store.
Have you any example of that ? How can i pass store into defer or done function ? Thxs
@usopan this worked for me
fetch: ({ dispatch, path, params: { slug } }) => dispatch(getSomething(path))
Hello,
I need to access store in the fetch, so as to pass an access token while doing a request. How do I do that?
Thanks