Skip to content
Advertisement

Tag: reactjs

How to add/remove items in a state in react based on a toggle?

I have a requirement to show products based on the checkbox toggles. If none is toggled, the array should be empty. If the men’s checkbox is toggled, men-related products will be shown, and the same for the women’s checkbox. If both are toggled, both related products will be shown. When the user is toggling men or women, the respective products

Firebase Firestore returns [object Object] instead of instead of a plain object

I have a custom hook called useDocument.js below which fetches the data from a firestore collection via a specific ID. Why is it that it’s returning [object Object] instead of plain object. I’ve tried accessing the name property and logging it to the console using document.name but throws up an error: Uncaught TypeError: Cannot read properties of null (reading ‘name’)

How to display an image from a string in react

I have featured_image that i get from an axios call, the image is saved in the src folder, src/img. It’s a string and it’s equal to “../img/blog1.jpg”. I can’t have the background image dispalyed i believe it needs to be converted to a static image somehow. Answer If you are using static images in react app you better should move

Why Gun.js duplicate messages in ReactJs

I’m implementing gun.js in react application.But messages are duplicated on each render, and on each update. Can someone help to figure out what’s wrong with my code. this my code . then in my component : get message on each new update send message function Answer My simple fix for that was add useRef()

Trigger parent API call from child in react

In my parent(Feed) I display a list of posts: The child(PostCompose) can create a post: The PostCompose component makes the requests to the backend to create the new posts, but how do I trigger the Feed to refresh to pull the new list of posts? I feel like my approach might need some work, any help would be great as

REACT- My condition is working partially why?

In my json file from my api, I have a variable apply, If apply:0, Then It should should print my data and If apply:1, Then It should hide my data (i.e row in my Table). Actually when I combine my 2 conditions, It is partially working :(applyStatus ? menus : menus.filter((i) => i.apply !== 1)) && (showGood ? menus :

I am trying to use the react hook useContext() but its not working

i am trying to use the useContext hook for the first time and i am not getting the name displayed on screen, i have never used useContext ever before, so pls a little bit of explination of my mistake will be appreciated. Here is the code: (edit: added App.js) AuthContext.js Header.js App.js i have added the error screenshot Answer Instead

Advertisement