I am trying to build a search box. When you type in it, it automatically filters my App.js file (Cards of robots). I have a separate, robots.js file in which I list the properties of the robots: My filter method works, when I only put a single property in it. In the code above, I am illustrating it when it
Tag: reactjs
How do I pass an array of objects that contains a component to child component in React with Typescript?
I need to make Accordion component reusable. In the future I should be able to add new object to the same array ‘accordionProps’ and pass it down to accordion. Here I’m passing an array ‘accordionProps’ of objects down to component. Prop types are defined in child component Accor…
Testing actions reliably
I’m using xstate to implement a login flow. I have a machine where the initialState invokes a Promise, and if it’s rejected it will redirect to a state that has an entry action. I would like to test that the action is called at the right time properly. machine.ts machine.spec.ts I managed to make …
Nextjs different slug names for the same dynamic path [closed]
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers. Closed las…
React, make a second API call based on a state set by a first api call
I am trying to build a weather app with OpenWeather API. I have to get the latitude and longitude based on a first API call that define the location by search. I have tried async/await and useEffect hook but failed in both cases. My code is below. What am I missing? Answer What you are missing is that when yo…
How to give Grid Items of a React Grid layout a reference
Im trying to have a dynamic array of references. These references would come from the Grid items, that are being mapped from a list to the Grid Layout-Element. This is my code: It seems like the “ref”-attribute gets ignored from react, because none of the grid items refs are being pushed into the …
Is this a good practice? [closed]
Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year. Improve this question I`m doing a project with react and I decided to make routes functionali…
How can I rewrite this conditional css using classnames?
In react component, I’m using css module and I got this conditional css that is working fine, but I would like to refactor it using classnames library. So I tried this but I get error msg saying active will always return false. I also tried styles.activeLabel: active === true, but I get another error me…
React Hook most proper ways to refactor resusable functions and effects
let’s consider two hook components: Despite being so similar, due to the nature of the context, we have to consider these hooks as different components, however, there is a lot of duplicated code to refactor and they even share the same code for some effects. Due to my experience with OOP, it is hard to…
Allow input type number only a number/float between 0-1
I want to have an input number that allows any float between 0-1 including both whole numbers. But it’s proving quite tricky just getting the backspace to actually delete a numbers as it comes as NaN I got this: Answer You can use achieve your goal with adding some conditions to the addRate state, also …