I have a problem with react-router-dom and Prompt. The problem is Prompt' (imported as 'Prompt') was not found. Has something changed in the new versions?
Here is my code:
import React from 'react';
import '../styles/ContactPage.css';
import { Prompt } from 'react-router-dom';
class ContactPage extends React.Component {
state = {
value: ''
}
handleSubmit = e => {
e.preventDefault();
this.setState({
value: '',
})
}
handleChange = e => {
this.setState({
value: e.target.value,
})
}
render() {
return (
<div className='contact'>
<form>
<h3>Send a form</h3>
<textarea value={this.state.value} onChange={this.handleChange} placeholder='write something'></textarea>
<button onSubmit={this.handleSubmit}>Send</button>
</form>
<Prompt when={true} message={"You did not end your form. Are you sure you want to change a page? All data will be lost"} />
</div>
);
}
}
export default ContactPage;
The documentation has a guide for upgrading from v5 to v6 which says:
<Prompt>is not currently supported
<Prompt>from v5 (along withusePromptanduseBlockerfrom the v6 betas) are not included in the current released version of v6. We decided we'd rather ship with what we have than take even more time to nail down a feature that isn't fully baked. We will absolutely be working on adding this back in to v6 at some point in the near future, but not for our first stable release of 6.x.
Stick to v5 if you want to use it.