I’m trying React hooks for the first time and all seemed good until I realised that when I get data and update two different state variables (data and loading flag), my component (a data table) is rendered twice, even though both calls to the state updater are happening in the same function. Here is my api function which is returning
Tag: reactjs
Jest testing with Node – Timeout – Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout
I’m starting to test my code with Jest, and I can’t make a seemingly simple test to pass. I am simply trying to check if what I receive from a Maogoose database request is an object. The function fetchPosts() is working because I hooked it up with a React frontend and it is displaying the data correctly. This is my
How to log out all tabs in one browser when one tab is logged out in React.js?
I’m new to React. I want to know how to auto log out all tabs in one browser when one tab is logged out in React.js.(not using redux) I use JWT and store JWT on local storage. Please any one help me on this. Thanks. Answer 1) On Component mount write this code and call the action on addEventListener when
trying to remove padding from the ul tag of the popup
when I click chip chipName=”button test IPA” a popup opens. I am trying to remove padding from the ul tag of that popup. but the problem is I am not able to find the ul tag in my html of jsx. I gave className in the react code but still I am not able to target can you please help
React + NodeJs Fetch issue
I am trying to fetch the following results of my api (which is working well) http://localhost:5000/api/continents into a react component (a simple array to begin with). Endpoint code extracted from server.js: Here is my continents.js code: And here is the App.js code: Issue: continents array is empty. No data fetched. However, there are no errors. I would very much appreciate
Make React useEffect hook not run on initial render
According to the docs: componentDidUpdate() is invoked immediately after updating occurs. This method is not called for the initial render. We can use the new useEffect() hook to simulate componentDidUpdate(), but it seems like useEffect() is being ran after every render, even the first time. How do I get it to not run on initial render? As you can see
Received a promise that resolves to: undefined. Promise elements must resolve to a class or function
I am trying to use lazy loading in react. I have imported lazy and Suspense components from react. The page doesn’t show anything again. but the error I got is: Expected the result of a dynamic import() call. Instead received: [object Object]. Element type is invalid. Received a promise that resolves to: undefined. Promise elements must resolve to a class
How to test snapshots with Jest and new React lazy 16.6 API
I have to components imported with the new React lazy API (16.6). In my tests, I’m doing the snapshots of this component. It’s a very straightforward test: In the logs, the test is failing with this error: Do I have to wrap in every single test suite with <Suspense>…? If I do that, I only see in the snapshot the
When should you NOT use React memo?
I’ve been playing around with React 16.6.0 recently and I love the idea of React Memo, but I’ve been unable to find anything regarding scenarios best suited to implement it. The React docs (https://reactjs.org/docs/react-api.html#reactmemo) don’t seem to suggest any implications from just throwing it on all of your functional components. Because it does a shallow comparison to figure out if
Cannot fix eslint rule on indenting case statements in switch statement
Here is a screenshot of my sublime text window showing the eslint error being thrown for the switch / case statement. I want to have to indent 4 spaces, as the code shows. and here are 4 different attempts to try to allow for an indent of 4 spaces, via modifications in the .eslintrc file in my react app. I