react-hooks Questions
8
Solved
on react docs forms section there is the following example using class components:
class Reservation extends React.Component {
constructor(props) {
super(props);
this.state = {
isGoing: true,
...
Safelight asked 2/9, 2020 at 17:33
1
I just build a next.js application in that I use react context and react reducer to authenticate users and this is my context code:
import React from "react";
import { createContext, useC...
Barrens asked 10/12, 2022 at 15:6
13
Solved
I have a component that looks like this (very simplified version):
const component = (props: PropTypes) => {
const [allResultsVisible, setAllResultsVisible] = useState(false);
const renderR...
Hyperesthesia asked 10/4, 2019 at 23:45
9
Solved
How to push element inside useState array React hook?
Is that as an old method in react state? Or something new?
E.g. setState push example ?
Prouty asked 13/2, 2019 at 18:21
11
I'm using Enzyme's shallow method to test a component which uses the useParams hook to get an ID from the URL params.
I'm trying to mock the useParams hook so that it does't call the actual method...
Liederman asked 15/11, 2019 at 19:33
22
Solved
I am trying to learn hooks and the useState method has made me confused. I am assigning an initial value to a state in the form of an array. The set method in useState is not working for me, both w...
Skimmer asked 7/1, 2019 at 6:5
7
Consider the following example:
const userRole = sessionStorage.getItem('role');
const { data, setData, type, setTableType } = useTable([]);
useEffect(() => {
const getData = async () => {
...
Outlawry asked 16/7, 2020 at 20:41
3
Solved
I am quite new to react and have problems in understanding the useState Hook - or more specifically the aspect of the previousState.
A normal useState Hook, and probably most common example, looks ...
Engelhardt asked 11/9, 2020 at 18:49
2
Solved
I am studying react-hook recently. I have encountered a problem which makes me unable to understand in the process of practice.
import React, { useState, useCallback } from 'react';
const set = n...
Frizzle asked 16/11, 2019 at 10:17
4
I know the conventional way when using hooks is to fetch the data using the useEffect hook. But why can't I just call axios in the functional component instead of a hook and then set the data.
Bas...
Undertow asked 27/5, 2020 at 19:6
4
I am new in react and trying to learn redux. I want to access the store inside a class, but it gives me an error the I cant use hook in class.
When I use this code in function (as I saw in a YouTub...
Without asked 21/7, 2019 at 18:20
4
Solved
Trying to catch up on the React Hooks. I'm reading that they recommend the use of the Hook useReducer when dealing with a complex state. But my doubt starts from the following scheme:
Using React ...
Pegues asked 30/4, 2020 at 19:16
5
I am trying to get the text value from a dropdown select using {useState} in React Hooks. I just get the value (number) rather than the text.
I've copied the bits of code below which control the se...
Sclater asked 26/9, 2019 at 10:32
6
Solved
I'm trying to track element visibility with React/Hooks and the Intersection Observer API. However, I can't figure out how to set up observation with "useEffect". Does anybody have any idea how cou...
Seeto asked 11/10, 2019 at 12:58
5
Solved
I am quite new in React hooks, I am trying to replace the connect, mapStateToProps and so forth with useSelector, useDispatch. This is what I have:
import React from 'react';
import { useSelector ...
Sibie asked 30/3, 2020 at 18:27
3
Solved
I'm using Nextjs 13 with server actions. I have a form:
const [isUploadingDocs, setIsUploadingDocs] = useState<boolean>(false);
... rest of code ...
return (
<form
action={async (formData...
Shaddock asked 18/8, 2023 at 3:13
3
Solved
My problem is that I need the user to confirm if he wants to continue to close or refresh the page. If he press No, it won't close nor refresh the page.
Please take a look at my code so far:
useEff...
Bergerac asked 26/8, 2021 at 4:39
17
Solved
I've been playing around with the new hook system in React 16.7-alpha and get stuck in an infinite loop in useEffect when the state I'm handling is an object or array.
First, I use useState and in...
Preteritive asked 30/10, 2018 at 18:45
4
Solved
Let's say I have this simple dummy component:
const Component = () => {
const [state, setState] = useState(1);
setState(1);
return <div>Component</div>
}
In this code, I updat...
Mccoy asked 11/10, 2022 at 20:54
11
Is there an easy way to determine which variable in a useEffect's dependency array triggers a function re-fire?
Simply logging out each variable can be misleading, if a is a function and b is an o...
Dictionary asked 15/3, 2019 at 17:6
2
Solved
I'm building a custom hook where I want to add an event listener to a ref, but I'm not sure how to clean up properly, since listRef and listRef.current could be null:
export const myHook: MyHook =...
Zacynthus asked 3/3, 2020 at 18:5
6
I try to import the chatbotcontext in order to get access to current chatbot in edit, but something went wrong. Do you have ideas what could be the issue here?
Here is the error message:
Here is a...
Prosperus asked 31/3, 2020 at 8:46
3
Solved
I'm not using typescript in my reactjs project, but I still want to document my components with JSDocs.
The problem where is that I have a functional component with React.forwardRef and I want to c...
Saddletree asked 31/7, 2020 at 17:33
3
Solved
Hi I recently learned the new react toolkit with the rtk query tool, and I am trying to put in a login system together using the createApi from the rtk package.
After giving it a test on the login ...
Bennir asked 28/8, 2021 at 1:46
8
Solved
I'm expecting state to reload on props change, but this does not work and user variable is not updated on next useState call, what is wrong?
function Avatar(props) {
const [user, setUser] = React...
Haematogenesis asked 25/2, 2019 at 12:1
© 2022 - 2024 — McMap. All rights reserved.