Question: Why call component ReduceToggle and not ReduceMotionToggle?
ReduceToggle
ReduceMotionToggle
Bonus: Here is the same component made with hooks (I just love hooks)
import React, { useState, useEffect } from 'react' const ReduceToggle = () => { const [ checked, setChecked ] = useState(false) // componentDidMount() useEffect(() => { const reduceMotionOn = localStorage.getItem('reduceMotionOn') if (typeof reduceMotionOn === 'string') { reduceMotionOn = JSON.parse(reduceMotionOn) } if (reduceMotionOn === null) { localStorage.setItem('reduceMotionOn', false) } setChecked(reduceMotionOn) }, []) // Handle toggle change const toggleChecked = event => { localStorage.setItem('reduceMotionOn', event.target.checked) setChecked(event.target.checked) } return ( <div className="toggle"> <input id="reduce-motion" type="checkbox" checked={checked} /> <label htmlFor="reduce-motion">Reduce Motion</label> </div> ) } export default ReduceToggle
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Question:
Why call component
ReduceToggle
and notReduceMotionToggle
?Bonus:
Here is the same component made with hooks (I just love hooks)