1×
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

    Read a Value from Recoil with useRecoilValue

    reactReact

    To get a value from Recoil we can import the atom that we want and the hook useRecoilValue from recoil.

    Then we can get the value:

    import { useRecoilValue } from 'recoil'
    ...
    import { gameScore } from './atoms'
    ...
    const score = useRecoilValue(gameScore)

    And display it in a lablel:

    <h3>Score: {score}</h3>

    That value will update every time the button is clicked (and setScore is called) automatically!