Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

if back react

import { useHistory } from 'react-router-dom'


const [ locationKeys, setLocationKeys ] = useState([])
const history = useHistory()

useEffect(() => {
  return history.listen(location => {
    if (history.action === 'PUSH') {
      setLocationKeys([ location.key ])
    }

    if (history.action === 'POP') {
      if (locationKeys[1] === location.key) {
        setLocationKeys(([ _, ...keys ]) => keys)

        // Handle forward event

      } else {
        setLocationKeys((keys) => [ location.key, ...keys ])

        // Handle back event

      }
    }
  })
}, [ locationKeys, ])
Comment

PREVIOUS NEXT
Code Example
Javascript :: package json scripts multiple commands 
Javascript :: javascript fill array from 0 to n 
Javascript :: filter array of even numbers 
Javascript :: tsconfig.json not generated 
Javascript :: move element jquery 
Javascript :: javascript clear radio button 
Javascript :: js iterate match indexes 
Javascript :: read json file into object javascript 
Javascript :: javascript cookies store object 
Javascript :: react aws s3 npm 
Javascript :: js math.random 
Javascript :: js remove the last character from a string 
Javascript :: how to downgrade node version 
Javascript :: angular build aot vs jit 
Javascript :: install swagger jsdoc 
Javascript :: delay input javascript 
Javascript :: get all cookies 
Javascript :: jquery ajax responsetext 
Javascript :: how to get dropdown selected value in javascript onchange 
Javascript :: js array to csv 
Javascript :: how to send a message using discord.js 
Javascript :: regexp object javascript 
Javascript :: jquery get value of input submit 
Javascript :: post message in iframe javascript 
Javascript :: number to word js 
Javascript :: how to remove timezone from date in javascript 
Javascript :: dynamic folder import javascript 
Javascript :: loop over string js 
Javascript :: how to fill array with consecutive numbers javascript 
Javascript :: react in laravel 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =