react-transmit icon indicating copy to clipboard operation
react-transmit copied to clipboard

Passing props to Transmit

Open joa-queen opened this issue 8 years ago • 4 comments

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 
        }
    }
});

joa-queen avatar Feb 23 '16 14:02 joa-queen

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 
        }
    }
});

carlosvillu avatar Feb 23 '16 15:02 carlosvillu

It doesn't work.

Am I missing something in my routes definitions?

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

joa-queen avatar Feb 23 '16 15:02 joa-queen

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.

carlosvillu avatar Feb 23 '16 15:02 carlosvillu

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

joa-queen avatar Feb 23 '16 16:02 joa-queen