What do you want to save?
Add Code snippet
New code examples
-
Javascript 2021-10-19 11:05:08
apply back button to a react component
import { useHistory } from "react-router-dom"; export const Item = () => { let history = useHistory(); return ( <> <button onClick={() => history.goBack()}>Back</button> </> );... Add solution -
Javascript 2021-10-06 13:54:03
chrome back button click event react
import { useHistory } from 'react-router-dom' const [ locationKeys, setLocationKeys ] = useState([]) const history = useHistory() useEffect(() => { return history.listen(location => { if (history.action === 'PUSH') { setLocationKeys([... Add solution -
Javascript 2021-10-02 10:07:03
in react js how to access history in component
import { useHistory } from "react-router-dom"; function HomeButton() { let history = useHistory(); function handleClick() { history.push("/home"); } return ( <button type="button" onClick={handleClick}&g... Add solution -
Javascript 2021-09-21 16:50:05
react router remove location state on refresh
import createHistory from 'history/createBrowserHistory' ... componentDidMount(){ const history = createHistory(); if (history.location.state && history.location.state.transaction) { let state = { ...history.location.state }; ... Add solution -
Javascript 2021-09-15 18:20:03
how to redirect back to previous page onClick react router
import { useHistory } from 'react-router-dom'; function app() { let history = useHistory(); const redirect = () => { history.push('/your-path') } return ( <div> <button onClick={redirect}>Redirect</button> ... Add solution -
Javascript 2021-09-15 07:03:04
difference between useHistory and props.history
//You can use useHistory() in any component, //but props.history only in components where the history is available in props //When you use history.push, you do NOT have to specify the pathname. const queryString = new URLSearchParams(params).toString(... Add solution -
Javascript 2021-09-15 02:47:02
Programmatically navigate using react router
import { useHistory } from "react-router-dom"; function HomeButton() { let history = useHistory(); function handleClick() { history.push("/home"); } return ( <button type="button" onClick={handleClick}&g... Add solution