All Questions
Tagged with react-native react-hooks
2,018
questions
219votes
14answers
310kviews
What is useState() in React?
I am currently learning hooks concept in React and trying to understand below example.
import { useState } from 'react';
function Example() {
// Declare a new state variable, which we'll call &...
189votes
18answers
297kviews
How can I force a component to re-render with hooks in React?
Considering below hooks example
import { useState } from 'react';
function Example() {
const [count, setCount] = useState(0);
return (
<div>
<...
116votes
8answers
123kviews
How to register event with useEffect hooks?
I am following a Udemy course on how to register events with hooks, the instructor gave the below code:
const [userText, setUserText] = useState('');
const handleUserKeyPress = event => {
...
71votes
5answers
73kviews
Where can I make API call with hooks in react?
Basically we do API calls in componentDidMount() life cycle method in React class components like below
componentDidMount(){
//Here we do API call and do setState accordingly
}
...
69votes
5answers
43kviews
Storing non-state variables in functional components
Below are two React Components that do almost the same thing. One is a function; the other is a class. Each Component has an Animated.Value with an async listener that updates _foo on change. I need ...
56votes
6answers
77kviews
react-navigation: Detect when screen, tabbar is activated / appear / focus / blur
Perviously when I wanted to make some actions when screen is opened I put them inside componentDidMount. For example I can fetch some data.
like this.
componentDidMount() {
this.updateData();
}
...
31votes
3answers
34kviews
What’s the difference between useState and useEffect?
I have seen these two new concepts introduced in react v16.
As per my understanding:
useState is similar like setState with hooks and useEffect works similarly like life cycle methods.
Is my ...
25votes
3answers
44kviews
How can I bind function with hooks in React?
Basically we bind event handler functions in constructor or make them as arrow functions in React class components like below
class Test extends Component{
constructor(props){
super(props);
...
20votes
3answers
15kviews
React Native onLayout with React Hooks
I want to measure the size of a React Native View every time it renders, and save it to state. If element layout didn't change the effect should not run.
It's easy to do with a class based component,...
18votes
4answers
15kviews
How to use lifecycle methods with hooks in React?
I have gone through hooks introduced in react v16.7.0.
https://reactjs.org/docs/hooks-intro.html
So my understanding about hooks is we can play with state in functional component without writing ...
18votes
3answers
3kviews
How to create a custom hook that recives dependencies?
I'm making a custom hook that have a toogle when some state change.
You should be able to pass any state in an array.
import { useState, useEffect } from 'react'
const useFlatListUpdate = (...
17votes
3answers
54kviews
How to setInterval for every 5 second render with React hook useEffect in React Native app?
I have React Native app and I get data from API by fetch. I created custom hook that get data from API. And i need to re-render it every 5 seconds. For it I wrapped my custom hook to setInterval and ...
16votes
5answers
45kviews
how to set state array using react hooks
Thanks in advance.
I have a state array as below.
I need to add an item to state array, I came across that we need not do state mutation. How do i set state with prevState.
const [messages, ...
16votes
4answers
6kviews
Better way to use multiple context providers in ReactNative
I am having an app in which I am using 3 Context Provider. For the app to work, I have to wrap <App/> in all these providers. As my app grows I am expecting to have a few more providers for ...
15votes
2answers
7kviews
React Hooks Const Component vs Functional Component
I understand the difference between a functional component and a class component, but what's the difference between const component to a functional component?
e.g
const Home = () => {
return (
...