()
| 9 | const userIds = [1, 2]; |
| 10 | |
| 11 | const Demo = () => { |
| 12 | const [userId, setUserId] = useState(userIds[0]); |
| 13 | const [isAdmin, setIsAdmin] = useState(false); |
| 14 | |
| 15 | // This artificially slows down rendering |
| 16 | let now = performance.now(); |
| 17 | while (performance.now() - now < 200) { |
| 18 | // Do nothing for a bit... |
| 19 | } |
| 20 | |
| 21 | useLayoutEffect(() => { |
| 22 | setIsAdmin(userId === userIds[0]); |
| 23 | }, [userId]); |
| 24 | |
| 25 | const handleChange = () => { |
| 26 | const otherId = userIds.find((id) => id !== userId)!; |
| 27 | setUserId(otherId); |
| 28 | }; |
| 29 | |
| 30 | return ( |
| 31 | <div className='tutorial-shorts'> |
| 32 | <p>userId: {userId}</p> |
| 33 | <p>Admin: {isAdmin}</p> |
| 34 | <Button title='Change User' onClick={handleChange} /> |
| 35 | </div> |
| 36 | ); |
| 37 | }; |
| 38 | |
| 39 | export default Demo; |
nothing calls this directly
no outgoing calls
no test coverage detected