Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Passing props to Transmit #59

Open
joa-queen opened this issue Feb 23, 2016 · 4 comments
Open

Passing props to Transmit #59

joa-queen opened this issue Feb 23, 2016 · 4 comments

Comments

@joa-queen
Copy link

Hi, I want to send props from the server to Transmit (I'm using the react-isomorphic-starterkit).

Si I have this on server:

renderProps.auth = 'authstring'
Transmit.renderToString(ReactRouter.RoutingContext, renderProps).then(({reactString, reactData}) => {
...
});

And then in my component definition, I have the following:

export default Transmit.createContainer(AppWrapper, {
    initialVariables: { },
    fragments: {
    doSomething: () => {
            //Want to read my authstring here 
        }
    }
});
@carlosvillu
Copy link

Maybe you need do something like this:

const AuthRoutingContext = (props) => {
  return (< RoutingContext {...props} variables={{auth: 'authstring'}}) />
} 

Transmit.renderToString(AuthRoutingContext, renderProps).then(({reactString, reactData}) => {
...
});

And then

export default Transmit.createContainer(RoutingContext, {
    initialVariables: {
      auth: ''
    },
    fragments: {
    doSomething: ({auth}) => {
            //Want to read my authstring here 
        }
    }
});

@joa-queen
Copy link
Author

It doesn't work.

Am I missing something in my routes definitions?

module.exports = (
    <Router component={AppWrapper}>
        <Route path="/" component={Main} />
    </Router>
);

@carlosvillu
Copy link

You have to do the same, but in your AppWrapper in the router.

const AppWrapperRouter = (props) => {
  return (<AppWrapper {...props} variables={{auth: 'authstring'}}) />)
}
module.exports = (
    <Router component={AppWrapperRouter}>
        <Route path="/" component={Main} />
    </Router>
);

That will work for sure.

@joa-queen
Copy link
Author

The thing is that I need 'authstring' to come from the server.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants