react-hooks Questions

3

I have the following custom hook which stores data in the localstorage: import { useCallback, useEffect, useState } from "react"; export const useLocalStorage = (key, initialValue) =>...
Occlusive asked 16/8, 2021 at 20:25

5

Solved

I'm using React hooks for app state, I wondered about how to initialize the function component state using props? The useState hook doc says something definitive like, const [count, setCount] = use...
Emaciated asked 11/12, 2019 at 15:53

2

Can you explain me why useContext() works for me if I don't wrap my components with Context.Provider? I just exported result of "createContext(someValues)" with predefined values and call...
Lampoon asked 25/4, 2022 at 19:34

10

Solved

If we want to restrict useEffect to run only when the component mounts, we can add second parameter of useEffect with []. useEffect(() => { // ... }, []); But how can we make useEffect to ru...
Airel asked 9/3, 2019 at 8:53

0

I make an API call in my submit handler (async function). In case of error, I show an alert and then re-throw from the catch block, so that monitoring tools like Sentry can report it. To disable th...
Downcome asked 13/3, 2023 at 18:28

3

Solved

Looking at React's useMemo documentation. They say to use it when you need to compute an expensive calculation. This optimization helps to avoid expensive calculations on every render. I looke...
Peppers asked 29/3, 2019 at 12:49

3

Solved

I was looking around, but couldn't find any related Q&A out there. I'm building a project in ReactJS with tailwindCSS, and implementing dark mode to the site. Everything works fine, but now I h...
Lebna asked 18/8, 2021 at 15:56

7

Solved

I found that there are several ways to handle user's text input with hooks. What is more preferable or proper way to handle an input with hooks? Which would you use? 1) The simplest hook to handle...
Leonidaleonidas asked 19/4, 2019 at 6:52

5

Solved

FOREWORD / DESCRIPTION I am trying to use React's new hooks feature for an e-commerce website that I am building, and have been having an issue working a bug out of my shopping cart component. I ...
Miguelmiguela asked 8/3, 2019 at 2:17

1

Solved

I'm following a guide I found on StackOverflow to sort an array in order to change the column order desc/asc of a table I'm populating with an API. I'm using this Stack answer: sort an array with r...
Wolfson asked 7/3, 2023 at 22:26

3

Solved

I'm trying to dynamically pass the width to a component's styles. On first load, it's okay, but if I resize it never re renders the component, even though the hook is working. I read about that si...
Lazes asked 25/3, 2020 at 16:57

6

Solved

I took the example from the documentation : import React from "react"; import { useForm } from "react-hook-form"; export default function App() { const { register, handleSubmi...
Agitprop asked 9/5, 2021 at 9:12

7

Solved

Scenario I have a custom hook that returns an action. The parent component "Container" utilized the custom hook and pass the action as prop to a children component. Problem When the action is e...
Firry asked 26/2, 2019 at 19:3

2

Solved

Sorry for just a basic question, But I'm a little stuck here to find any way to get values from React Select after making a selection. This is a Simple Selection setup. const selectOptions = [ { ...
Cottle asked 12/2, 2022 at 18:15

6

I am new to Tailwind CSS and CSS in general. I need to make my buttons stop doing transform/transition effects when they are disabled. Currently, the disabled color changes are getting applied but ...
Petterson asked 14/10, 2021 at 21:18

3

Solved

I am building my React App and suddenly I get the following error: Error: Minified React error #321; visit https://reactjs.org/docs/error-decoder.html?invariant=321 for the full message or use the...
Ellerey asked 2/12, 2020 at 13:44

3

Solved

I need to connect to WebSockets server and log it's messages. With React class component I'd put this logic in componentDidMount lifecycle hook and move on happily, but I'm not sure how to properly...
Litchfield asked 10/2, 2020 at 14:55

4

This is my first time to develop a react application. I tried to implement checkboxes in each row of a table and check which of the rows are selected. I used useState hook to make checked and onCh...
Margaretmargareta asked 29/5, 2019 at 9:6

4

I have a faceted search component that I am building. I am having trouble figuring out how and where to handle state. Solution #1 A parent component manages state - uses a reducer to manage all co...

4

Solved

With regular React it's possible to have something like this: class NoteEditor extends React.PureComponent { constructor() { super(); this.state = { noteId: 123, }; } componentWillUnmoun...
Beanstalk asked 28/2, 2020 at 17:39

3

Solved

I have a search box that I can copy and paste a column from excel. I parse the input and generate an array of the entries. I am then mapping over the entries and calling a custom hook with each it...
Colicweed asked 2/9, 2019 at 0:8

2

The question applies for both Class and function based components. This is probably an way too easy question, but for some reason I can't find a concise definite answer so I sometimes get thrown of...
Aflutter asked 22/4, 2020 at 19:38

4

Solved

I have a react web app with a theme toggle on the navigation. I have a ThemeProvider Context that has logic to auto detects a user's System theme preference and sets it. However, I feel a user shou...
Franko asked 9/4, 2020 at 9:7

3

Solved

I am using React Router v6 in an application. I have a layout page, which uses an outlet to then show the main content. I would also like to include a title section that changes based on which path...
Wed asked 10/1, 2022 at 15:49

1

Solved

I am getting the following error during sonarqube scan: Do not define components during render. React will see a new component type on every render and destroy the entire subtree’s DOM nodes and s...
Proximity asked 10/2, 2023 at 16:57

© 2022 - 2024 — McMap. All rights reserved.