Created
September 19, 2019 10:04
-
-
Save raibima/0ffc366d7e1a2fea5a4858274daee633 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { useEffect, useState } = React; | |
| export default function IndexPage(props) { | |
| const [currentHash, setCurrentHash] = useState(window.location.hash); | |
| useEffect(() => { | |
| function handleHashChange(e) { | |
| setCurrentHash(window.location.hash); | |
| } | |
| window.addEventListener('hashchange', handleHashChange); | |
| return () => { | |
| window.removeEventListener('hashchange', handleHashChange); | |
| } | |
| }, []); | |
| return ( | |
| <main> | |
| <h1>Index Page</h1> | |
| <h2>{`Current hash: ${currentHash}`}</h2> | |
| <button onClick={() => { | |
| location.hash = "foo"; | |
| }}> | |
| Add hash | |
| </button> | |
| </main> | |
| ) | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment