udacity / reactnd-contacts-complete

Code-along project for the Contacts app
https://www.udacity.com/course/react-nanodegree--nd019
170 stars 579 forks source link

src/App.js: Failed to compile Unexpected use of 'history' no-restricted-globals #5

Closed tommulkins closed 6 years ago

tommulkins commented 6 years ago

The history prop passed into the render function then used to history.push("/") appears to break due to history being a restricted global keyword. Unfortunately //eslint-disable-next-line before history.push() does not fix the problem. Calling onCreateContact will then complain "TypeError: history.push is not a function."

I'm using Firefox Developer Edition 59.0b3 on Linux.

tommulkins commented 6 years ago

Oops, PLEASE IGNORE: I did not pass the history prop to the correct render method. Passing it to render function in the Route component works just fine.

oyeolamilekan commented 6 years ago

please show me how

deepio commented 5 years ago

Not saying this is what was meant or what is the best practice, but you can pass things around this way.

# In App
<NavBar location={location} history={history} expanded={expanded}/>
# In NavBar
...
if (this.props.location.pathname !== to) {
            this.props.history.push(to);}
        }}
...