Skip to content

Tag: reactjs

UseEffect won’t use updated state

I have a react function which is supposed to be my header. This header shall change its background color after reaching a button on scroll. To do so I use a scroll event listener and track its position in relation to the button. This works fine for setTransparent(false), but not for setTransparent(true): Logg…

React hooks callback ref pattern

I often face this situation with react callbacks: The problem is. I consider my component should only load one time. And with useEffect, i have to set onLoad in the dependencies, this cause any change to the onLoad prop to trigger the effect. I generally solve this issue with a ref It works well and solve a l…

Regex for String in React

How shall we write a regular expression to validate a string that should have a length of a minimum of 1 character and a maximum of 50 characters, have both upper case and lower case, alphanumeric, include space, and have mostly used special characters like @,._-&$#? The first character should be either a…