Category : react-hooks

I am calling an event listener inside a function in React hooks – not using useEffect and removing it inside the same function which is called when event fires, is there anything wrong with that? Example : – const handleMyEvent = () => { … … const element = document.querySelector(‘myDiv’); if(element){ element.addEventListener(‘mousemove’, handleMouseEvent); } } ..

Read more

I’m in a position where I cannot use useState or useEffect in react. If I use useState it triggers infinite renders I cannot use useEffect because I need state to do something. Example: export default function MyApp(props) { const [options, setOptions] = useState([]); const renderBody = (index) => { var temp = []; temp.push(props.data.results[index].correct_answer); props.data.results[index].incorrect_answers.forEach((current) ..

Read more

I want to remove the faint border from the bottom of the header in React Native. I’m using useLayoutEffect() hook to modify the header but unable to remove the border. I’ve tried using borderBottomWidth: 0 inside "headerStyle" but it’s not working. useLayoutEffect(() => { navigation.setOptions({ title: "Signal", headerStyle: { backgroundColor: "#fff", borderBottomWidth: 0 }, headerTitleStyle: ..

Read more