44 questions
-5
votes
1
answer
105
views
React runs useState update twice, possibly due to strict mode, need some details [closed]
this is my code for a vite react + ts calendar
import Day from "./Day";
import style from "./Calendar.module.css";
import { useState } from "react";
import type { ...
0
votes
1
answer
39
views
Is there a reliable way to handle a Route Path losing focus? Like onBlur
In an electron-vite, React, typescript app, I'm using a Router with paths to a series of pages, each of which returns a <RootLayout.
ReactDOM.createRoot(document.getElementById('root') as ...
1
vote
2
answers
120
views
StrictMode + useEffect creates two items in LocalStorage
I am currently working on a pokemon team builder. The issue I have is the following:
On my SelectedTeamBanner component I have an effect that should check if user has any team stored on localStorage. ...
0
votes
1
answer
66
views
Why is the effect not called twice in strict mode?
I was walking through some code and came across the following snippet to prevent StrictMode from calling an effect twice. While it's generally not recommended to implement such a feature, I was more ...
1
vote
0
answers
30
views
axios inside useLayoutEffect with StrictMode fires twice [duplicate]
I'm new to React and found a strange behavior inside useLayoutEffect function in my custom context (AuthContext - simple context to work with jwt and refresh token).
The problem: axios inside ...
0
votes
0
answers
31
views
React useEffect proper cleanup when adding event listeners [duplicate]
The question/solution already employs what I think is proper cleanup for the double mount for the StrictMode highlighted in simlar question.
Below is simplified example. The real code works with event ...
1
vote
1
answer
68
views
What is the react strict mode control flow
What will be the output of the following component under react strict-mode?
import { useEffect } from "react";
export default function Learn() {
let x = 1;
console.log("outside ...
-2
votes
1
answer
96
views
How do I control the double rendering caused by StrictMode in my React application?
I have a simple React application in which the index.js file looks like this:
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
const ...
1
vote
1
answer
51
views
How to explain the rendering result of a react component in strict mode?
The component is from React's official documentation's section Keeping Components Pure.
let guest = 0;
function Cup() {
// Bad: changing a preexisting variable!
guest = guest + 1;
return &...
0
votes
4
answers
3k
views
Should we call an API inside useEffect in React? [closed]
I heard that it is not a good practice to call an api inside useEffect, also thats why in dev mode useEffect runs twice.I am not sure about it, but if not useEffect, then what else?
Need fellow devs ...
1
vote
1
answer
43
views
When I use a class method to update state of a model in React it fires twice in strict mode
Does that mean that I am doing something wrong?
I thought strict mode was to help you find side effects.
If I turn off strict mode I get the quantity updated correctly (once per click). With strict ...
1
vote
0
answers
541
views
React Strict Mode causing issues during development
I have this Skip component to conditionally skip pages. I noticed that instead of skipping ONE page, it skips two pages! I suspected that it might be the Strict Mode running the UseEffect code twice. ...
2
votes
0
answers
69
views
React Strict mode is missing letters in my Next.JS typed text carousel component
I have a react component that receives an array of strings (facts).
The component cycles through the array and displays each fact individually.
Each fact is presented letter by letter as though being ...
1
vote
1
answer
6k
views
Dropdown overlay is deprecated - antd 5 migration issue
We use antd 4.22.8 in our project and upgraded React from 17 to 18 recently. At this point, some antd basic stuff (such as tooltips and checkboxes) stopped to work under certain circumstances in ...
1
vote
2
answers
57
views
Does change in state unmount functional component
I know that change in state triggers re-rendering of component. So my question is that, does change in state also unmount function component as part of re-rendering process?
main.jsx
const Fullnote = (...
1
vote
1
answer
681
views
StrictMode + SetInterval = double renders (even with useEffect cleanup)
I'm trying to explain to another engineer how React StrictMode works - with specific reference to double renders, intervals and useEffect cleanups.
Take the following simple counter component:
const ...
0
votes
1
answer
40
views
Cannot get React to complain about a non-pure function
I was reading the official docs on: https://react.dev/learn/keeping-components-pure#detecting-impure-calculations-with-strict-mode
It talks about using:
<StrictMode>
<App />
</...
0
votes
1
answer
35
views
Error : Expected to return a value at the end of arrow function
Expected to return a value at the end of arrow function , this is a common problem one can face easily while using react JSX in strict mode
contentType = id => {
console.log('')
if (id === '...
2
votes
1
answer
807
views
How to fix React calling `setState` twice in `useEffect` that has an empty dependency array in strict mode?
const { createRoot } = ReactDOM;
const { StrictMode, useEffect, useState } = React;
function Test() {
const [count, setCount] = useState(0);
useEffect(() => {
setCount((prevCount) => ...
0
votes
1
answer
982
views
useRef behavior is different in strict mode and non-strict mode in React 18 development
const { Fragment, StrictMode, useRef, useState } = React;
const { createRoot } = ReactDOM;
function CountLabel({ count }) {
const prevCount = useRef(count);
console.log("prevCount: ", prevCount....
2
votes
1
answer
951
views
Re-rendering with <React.Strict Mode> and fabric's canvas instantiation
I am creating a fabric canvas and buttons that instantiate shapes that should be selectable. I don't understand why my component is being re-rendered twice in the following scenario. Because of this ...
0
votes
1
answer
321
views
Why react strictmode initializes localstorage
Before removing strictmode
index.js
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
const root = ReactDOM.createRoot(...
0
votes
2
answers
268
views
React.StrictMode and createRoot influence my UI render
I am new to react. This is a generated code block in my project by create-react-app
const container = document.getElementById("root");
const root = createRoot(container);
root.render(
<...
1
vote
1
answer
301
views
How to solve Strict Mode Re-render issue [duplicate]
I have react code that works like so:
const [screenStream, setScreenStream] = useState(null);
useEffect(() => {
getPermissionsAndStreams();
}, []);
const getPermissionsAndStreams = () ...
1
vote
0
answers
106
views
Unexpected React behavior in Strict Mode
The following React component is rendered every 50ms. The value of s increases by 1 every second. When it does, I'd like to add the value of word to an array in state.
When the code runs, the word ...
0
votes
2
answers
2k
views
How to connect socket io in useEffect in React 18?
I just updated to React 18 and I noticed that the useEffect runs twice which makes my socket.io code fail connection. What could be the solution for this?
Here is my useEffect:
useEffect(() => {
...
0
votes
0
answers
874
views
Removing "React Strict Mode" solved my error. Is this is a budge?
I've found Why is my React component is rendering twice? which fixed my coding error (setState getting called X times depending in which component it gets called), but do I have a problem with my code ...
14
votes
1
answer
12k
views
Should I manualy disable React StrictMode in production?
I was reading the doc and learned that React StrictMode is for development only, and it explains why we have double invoke.
That's great, but does it mean I have to disable the StrictMode manualy for ...
23
votes
2
answers
72k
views
How to disable Strict Mode in React 18?
Simply, how can I disable Strict Mode in React 18? I'm using React 18 with create-react-app.
6
votes
1
answer
2k
views
React 18 StrictMode first useEffect wrong state
another React 18 strict mode question. I'm aware React will call the render and effect functions twice to highlight potential memory leaks with the upcoming features. What I yet don't understand is ...
10
votes
2
answers
7k
views
Can I keep <StrictMode> in my app but make it not render twice
I have my app inside a Strict Mode and it makes it difficult to run with my useEffect().
It basically logs all my values twice in the console which is not the result I want to achieve.
useEffect(() =&...
17
votes
1
answer
11k
views
Is there a way to check if React's `StrictMode` is on?
Is there a way in React -- either in code or via the React devtools -- to see if a component is being rendered in React's StrictMode? In my dream world, there would be some kind of constant I could ...
27
votes
6
answers
46k
views
React 18 strict mode causing component to render twice [duplicate]
The changes to strict-mode in React version 18 causes my code to render twice, which causes an error in axios abort controller, but I don't know how to clear the error from the browser console after ...
0
votes
1
answer
1k
views
React JS check whether strict mode is enabled
Is there any way to know whether the strict mode is enabled in React?
useEffect(() => {
if(strictModeEnabled) {}
})
I didn't find any information in the docs.
12
votes
2
answers
11k
views
Does strict mode work differently with React 18?
Consider the snippets below. With React 18, count gets printed twice to the console on every render but with React 17 it gets printed only once.
React 18 Example:
function App() {
const [count, ...
3
votes
2
answers
703
views
React Strict Mode
I am working on my project and i noticed that when strict mode is turned on it pushes two identical elements into my array. When the strict mode is off it pushes only one element into the array. Is ...
15
votes
3
answers
5k
views
Is it safe to change a ref's value during render instead of in useEffect?
I'm using useRef to hold the latest value of a prop so that I can access it later in an asynchronously-invoked callback (such as an onClick handler). I'm using a ref instead of putting value in the ...
10
votes
1
answer
3k
views
Should I use React.StrictMode in my test suite?
First time posting a question :)
I have a React application with:
// index.js
ReactDOM.render(
<React.StrictMode>
<Router>
<App />
</Router>
</React....
33
votes
1
answer
23k
views
findDOMNode is deprecated in StrictMode. findDOMNode was passed an instance of DraggableCore which is inside StrictMode
Draggable package is causing an error in strict mode:
Warning: findDOMNode is deprecated in StrictMode. findDOMNode was
passed an instance of DraggableCore which is inside StrictMode.
Instead, add a ...
16
votes
3
answers
57k
views
React / Reactstrap Warning: Legacy context API has been detected within a strict-mode tree
This is brand new install - I have not put any transitions on the Alert component
To replicate the code it is simple
import React from "react";
import { Alert } from "reactstrap";
export const ...
283
votes
7
answers
210k
views
My component is rendering twice because of Strict Mode
My React Component is rendering twice. So, I decided to do a line-by-line debug, and the problem is here:
if ( workInProgress.mode & StrictMode) {
instance.render();
}
React-dom....
167
votes
15
answers
387k
views
Warning: findDOMNode is deprecated in StrictMode. findDOMNode was passed an instance of Transition which is inside StrictMode
I am trying to use a function as a prop inside a component and this component is a child of another component. But the function is not working.? Can I know why. This is the warning i am receiving in ...
18
votes
3
answers
6k
views
How to disable react strict mode on third party libraries
We use strict mode in our React app. But third parties does not use strict mode. How can I achieve this?
95
votes
4
answers
93k
views
What is StrictMode in React?
I heard that strict mode helps to write React code in best practices way by throwing warnings for life cycle methods removal. I read about it from this article on Medium.
Is my understanding correct? ...