Skip to content

Latest commit

 

History

History

useRefresh

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

useRefresh

function useRefresh(): RefreshFunction
// with
type RefreshFunction = () => void

Provides a simple way to force a component to rerender.

Returns a function refresh which when called will force the component to rerender.

Note The effect of calling refresh is equivalent to updating a state in the component. The component is simply updated and is not unmounted and remounted again!

Usage

import React from 'react'
import {useRefresh} from 'react-tidy'

function App() {
  const refresh = useRefresh()
  return (
    <p>
      The time is {new Date()} <button onClick={refresh}>Refresh</button>
    </p>
  )
}