pyprism
pyprism

Reputation: 3008

React props is undefined

I am trying to pass props from one component to another via react-router.When I try to get that props from child component, I got this message TypeError: this.props.params.appState is undefined . Here is my code:

Tracks.jsx:

import { observable } from 'mobx';


export default class Tracks {
    @observable tracks = [];

}

app.jsx:

.......
import Tracks from './store/Tracks.jsx';

......
const appState = new Tracks();

ReactDOM.render(
    <Router history={browserHistory} >
        <Route path="/" component={Login} />
        <Route path="/dashboard" onEnter={authRequired} component={Main}>
            <Route path="album/create" component={AlbumCreate} />
            <Route path="album/:id" component={Album} appState={appState}/>
            <Route path="album/:id/upload"  component={Upload} />
        </Route>
    </Router>,
    document.getElementById('app')
);

Album.jsx:

.....
@observer
export default class Album extends React.Component {

    constructor(props) {
        super(props);
    }
componentDidMount () {
        console.log(this.props.params.appState.tracks);
    }

.....

Upvotes: 3

Views: 5066

Answers (1)

Kokovin Vladislav
Kokovin Vladislav

Reputation: 10391

change this

this.props.params.appState

to

this.props.route.appState

Params is dynamic segments of the URL, for props you need route

Upvotes: 6

Related Questions