Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Login extends React.Component {
- state = {
- redirectToReferrer: false
- };
- login = () => {
- fakeAuth.authenticate(() => {
- this.setState({ redirectToReferrer: true });
- });
- };
- render() {
- const { from } = this.props.location.state
- || { from: { pathname: "/" } };
- const { redirectToReferrer } = this.state;
- if (redirectToReferrer) {
- return <Redirect to={from} />;
- }
- return (
- <div>
- <p>You must log in to view the page at {from.pathname}</p>
- <button onClick={this.login}>Log in</button>
- </div>
- );
- }
- }
- class Login extends React.Component {
- constructor(){
- super();
- this.state = {
- redirectToReferrer: false
- };
- }
- ....
- }
- // BookContainer.js
- import { Container } from 'unstated'
- class BookContainer extends Container {
- state = {
- books: [],
- booksVisible: false
- }
- addBook = book => {
- const books = [...this.state.books, book]
- this.setState({ books })
- }
- toggleVisibility = () => {
- this.setState({
- booksVisible: !this.state.booksVisible
- })
- }
- }
- export {
- BookContainer
- }
Add Comment
Please, Sign In to add comment