useState setup
const initialState = calculateValue(props)
const [someStateVal, setSomeStateValue] = React.useState(initialState)Lazy Initialization
We can lazy initialize useState with a function like this:
const getInitialState = (props) => caluclateValue(props)
const [someStateVal, setSomeStateValue] = React.useState(initialState)In this case, React will only call the function when it needs the initial value. that is once at the time of the first render.
This is called “lazy initialization.”
Play with it or test it out here!
Also published on Medium: Javascript in Plain English
Keep reading

What fired my useEffect?
Developing in React brings its set of challenges, especially when dealing with side effects in functional components. React’s useEffect hook is a powerful tool but it can sometimes be a mystery figuring out which dependency change triggered a particular effect

Jest Spy on an Exported Function
The spyOn utility in Jest is incredibly versatile, enabling you to monitor, track, and even replace the behaviour of functions. However, applying this to a named export from a module can be a bit tricky due to the specific parameters required by spyOn
