Gatsby: Passing data between components

Created on 30 Apr 2018  路  2Comments  路  Source: gatsbyjs/gatsby

I'm trying to pass data that I'm getting from a 3rd party API using Link, but fail because

Warning: Unknown prop `user` on <a> tag. Remove this prop from the element. For details, see https://fb.me/react-unknown-prop
    in a (created by Link)
    in Link (created by GatsbyLink)
    in GatsbyLink (at new-project.js:20)
    in div (at new-project.js:30)
    in div (at new-project.js:28)
    in div (at new-project.js:25)
    in NewProject (created by ComponentRenderer)
    in ComponentRenderer (created by Route)
    in Route (created by Layout)
    in div (at index.js:17)
    in div (at index.js:8)
    in Layout (at index.js:6)
    in _default (created by ComponentRenderer)
    in ComponentRenderer (created by Route)
    in Route (created by withRouter(ComponentRenderer))
    in withRouter(ComponentRenderer) (created by Root)
    in ScrollContext (created by Route)
    in Route (created by withRouter(ScrollContext))
    in withRouter(ScrollContext) (created by Root)
    in Router (at root.js:145)
    in DefaultRouter (created by Root)
    in Root (at app.js:64)
    in AppContainer (at app.js:63)

Which means that I can't use the Link to pass data.

I know there has to be an easy way of passing data to a react component, but I can't figure out how if I don't use the Link component?

I'm trying to pass the selected option to another page? I'm missing something here.

````
render() {
const { selectedOption } = this.state
const data = this.props.data
const renderLink = selectedOption ? (


) : null

````

question or discussion

All 2 comments

Gatsby Link wraps React Router's Link, so you should be able to do something like:

<Link to={{
  pathname: '/create/project-title',
  state: { user: this.state.selectedOption }
}}>

Or maybe use a global store like https://github.com/gatsbyjs/gatsby/issues/5063

Was this page helpful?
0 / 5 - 0 ratings

Related issues

benstr picture benstr  路  3Comments

brandonmp picture brandonmp  路  3Comments

signalwerk picture signalwerk  路  3Comments

jimfilippou picture jimfilippou  路  3Comments

Oppenheimer1 picture Oppenheimer1  路  3Comments