Skip to content
Александр edited this page Jan 17, 2023 · 1 revision
export function useRef<T>(initial: T): { current: T }

Accepts the initial reference value.

import { afc, useForceUpdate, useRef } from 'react-afc'

function Component(props) {
  const count = useRef(0)
  const text = useRef(null)

  const forceUpdate = useForceUpdate()

  function changeRefs() {
    count.current++
    text.current = 'example'
    forceUpdate()
  }

  return () => <>
    <p>Count: {count.current}</p>
    <p>Text: {text.current}</p>
    <button onClick={changeRefs}>
      Change refs
    </button>
  </>
}

export default afc(Component)
Clone this wiki locally