ReactTraining / react-history

Manage session history with React
267 stars 23 forks source link

The history prop is undefined #18

Closed amirmohsen closed 7 years ago

amirmohsen commented 7 years ago

I was using version 0.13.3 of this package in my project. It was working fine, but I decided to upgrade to the latest (0.18.2) and that broke it. When I first load the page, the history prop is undefined.

<History basename={basename} keyLength={keyLength}>
    {({ history, action, location }) => {
        // history is undefined here
        return (
            <DispatchingRouter
                store={this.context.store || this.props.store}
                history={history}
                action={action}
                location={location}
                basename={basename}
                {...props}
            />
        );
    }}
</History>

I've ended up reverting back to 0.13.3 for now.

mjackson commented 7 years ago

Ah, my apologies for the breakage. 0.x days, you know :) Now you just get the full history object in the callback, and you can pull action and location off of it.

<History>
{history => {
  const { action, location } = history
  // ...
}}
</History>
amirmohsen commented 7 years ago

Thanks for the clarification.