I’m having a problem with my API request that always fails after page load. Don’t really know where Im wrong. Here’s my request and I call it when I interact with handleOpen function. ERROR: Answer It’s because your Ticker parameter is empty. When you create “stock”, clickedElement.ticker is undefined. Do this: Make getStock like like this:
Tag: react-hooks
“Cannot use import statement outside a module” error when importing react-hook-mousetrap in Next.js
Trying out Next.js but I’m struggling with the following. Just tried to install react-hook-mousetrap and imported it like I normally would: This gives me the following error: I am not sure what this means? I then thought it might be a problem with Nextjs’s SSR, since my library enables hotkeys and will use some browser APIs. If you already know
React Hooks: Passing state prop is NOT a function?
I am passing state hooks as props to my components and my ‘setCity’ works perfectly fine but when I try implementing setFlag I get an error saying “Searchbar.jsx:15 Uncaught TypeError: setFlag is not a function” So why can I set the value of city but not flag? I pass the props from ‘App’ to ‘footer’ which passes to ‘searchbar’. Answer
Why can’t I use dot notation on React State?
I’m creating a flashcard app and I’m currently trying to set the front side of the flashcard to some text from an API. My state: deckWithCards is a deck of flashcards and it looks like: When I do deckWithCards.cards I get: If I was to have 4 cards in a deck, I’ll get an array with 4 of these objects
Hook | Add Multiple List State
I define a list (useState ([])). I want to fill a list as data comes to index 0 of this list first. For example, a value comes every second and writes it on the list. then I want to press the button, create a new lite for the first index of the list and start filling it. How can I
What is wrong with the React components Route?
Attempting to build a flashcard app with React and React Hooks, I am able to get my home screen rendered. When introducing Router, I am able to click the link, update the path to be the one I am looking for, but nothing is being rendered from that new page. App.js ShowAllDecks.js –> List of flashcard decks Deck.js –> Individual
How to write a hook to load more button from fetching a json?
I am calling my fake api using fetch and getting Json data. How can I wire up my load more button so that it it loads more data? Everything works, I just need to add functionality to that load button. I have an empyt function… See code below: Answer So you already have all the data but you need to
React – how to apply local storage for hook value
I use the react-range package for personal purposes of my project, the problem is that I cannot save the value when the page is refreshed, I tried to use the local storage but I could not As you understand, I need to save the value using local storage, in addition, I will leave a link to mine on codesandbox link
Invoking function expression
I’m following a React-hooks tutorial and I don’t understand why does the function expression, timerId in the top useEffect is being invoked automatically, but the function expression, search, in the bottom useEffect requires it to be called search() in order to invoke it? Answer It is assigning a function to search variable which needs to be invoked manually. However in
Custom hook when taking data in next render lost data
I made a hook useSendFormData , when i use it i get Invalid hook call. Hook takes data from SubmitForm url:string, method: post or put success: success message if it was success id: not required but if item has id i is added to api call. auth default false Problem is it loses data on renders I don’t know how