All Questions
Tagged with conditional-rendering react-hooks
31 questions
0
votes
0
answers
64
views
React State Update Not Reflecting Immediately in Conditional Rendering
I am working on a React component where I need to select an item from a list and update the state with the selected item's ID. I then want to conditionally render the selected item. However, I am ...
0
votes
2
answers
851
views
React derived state. Whats wrong with this code
Coming from angular, i would like to know what's wrong with this code. I've been told that i should use useMemo (for the fitlering part) and useRef (to store products).
I know how to do that, but i ...
1
vote
0
answers
59
views
Conditional Rendering on BottomTab Navigator not working
So what i am trying to do is that I am doing conditional rendering of my AccountStack and AuthStack on my AccountTab, now my AuthStack contains screens Welcome, Login and Otp and after entering the ...
3
votes
3
answers
85
views
React: How to use conditional render and react-hooks to update another component's state?
I'm new to React. I'm trying to create a Login/Register Screen. I have three components called Login, Register and SlidingCard. I render these componenets on other jsx file called Screen. In ...
0
votes
2
answers
53
views
Why error message doesn't conditionally render?
username state
const [username, setUsername] = useState({
name: "",
isValid: true,
error_message:
"start with a letter \n allowed characters: a-z A-Z 0-9 - and _ "...
0
votes
1
answer
465
views
How to conditionally render a Login OR a Dashboard based on a user Redux state?
This is my code:
// Components
import Dashboard from './Dashboard';
import Login from './Authentication/Login';
import { Route } from "react-router-dom";
// Redux import { useSelector, ...
0
votes
1
answer
27
views
useState() for conditional styles
I am new to react and working on a project and was wondering how to change the theme of a single Footer component conditionally. Attached are the two themes I am trying to render. Here is the code I ...
2
votes
1
answer
177
views
I cant make a navigation bar to change its background only on main(/) content in REACT
I have a Header component like this
const [small, setSmall] = useState(false)
console.log(window.location.pathname)
console.log(window.location.pathname === '/')
useEffect(() => ...
0
votes
0
answers
324
views
React component appears and disappears instantly in conditional rendering
For following scenario :
When user don't have admin access, else case is rendering and disappearing instantly after it.
I can see blank page only after it.
How to resolve this scenario ?
function ...
2
votes
1
answer
1k
views
How do I use like & unlike functionality on every element while using map to render those elements?
I have social media posts stored in firebase and each post has a like button. I am using map() function to render those posts but I have declared a single state for like button using useState().
When ...
0
votes
0
answers
144
views
Conditional rendering in <td> for respective row when a button in that row is clicked
I want to implement a functionality where I can render the values of array and when I click on update for a particular record, conditional rendering should happen for some td's.
I have implemented ...
0
votes
1
answer
565
views
Conditional rendering with useEffect / useState, why is there a delay in the DOM when switching components?
Intro / Context
I am trying to build an application using React that allows for image or video display based on a chosen menu item. I am currently using Advanced Custom Fields within WordPress to ...
-1
votes
3
answers
645
views
How to conditionally render a component in react.js?
I am new to React and for my first project I'm trying to build an expense-tracker, by Traversy Media on YT.
I've thought to expand project a little bit by adding a date component to it. My current ...
0
votes
3
answers
3k
views
How to add if condition inside of useState in React
I want to add if condition inside of use state.
So here is my code example:
const [buttonName, setButtonName] = useState('Connect Wallet');
const changeButtonName = () => {
localStorage....
0
votes
2
answers
629
views
Is there any alternative way to call a react hook conditionally?
Using react hooks inside any function of condition is invalid. Neither can I do conditional rendering for a hook. Is there any way to use a hook with emplement condition? Please share code
1
vote
1
answer
367
views
How can I conditionally render this component based on whether or not there is data in localstorage?
I want MyList to render whatever is in localStorage (works great), however when there is nothing in local storage and I render the component, it renders empty. I would like to have a placeholder there ...
0
votes
1
answer
385
views
component not rendering after setState in React.js
I'm trying to render a component conditionally based on a particular state. The code below is inside of a mapping on another file. I have a setState const of open and whenever a user clicks the '...
2
votes
0
answers
177
views
How to test a component that renders conditional display?
I try to test a functional component which use useSelector hook to get data from state and renders according to the state.
I wrote a test for that component. It seems logical to me and it works. But I'...
1
vote
3
answers
569
views
Conditional rendering with every Update in text of search-field in a Todo List App
I have a react To Do list and i display an array of components when the app is first loaded and whenever a user types in some string in search field i wish to make an regex comparison and ...
1
vote
1
answer
616
views
How to hide element when device keyboard active using hooks?
I wanted to convert a hide element when keyboard active HOC I found to the newer react-native version using hooks (useEffect), the original solution using the older react lifecycle hooks looks like ...
1
vote
3
answers
3k
views
React.js: How to return the previous state value when cancel is clicked in a input field that changes the state [duplicate]
The parent component passes every prop, state and function, to the child component. Child component has no state or function of its own. Multiple of the same child component are rendered depending on ...
0
votes
0
answers
257
views
Conditional rendering with AND logical operator always returns true in React
I am doing a project where I want to close a dialog after the login is done in a async-await arrow function, for that I call the login function in a button and wait for the return (true if login its ...
1
vote
1
answer
1k
views
Re-Render Conditional Rendered Components in React
I have a component that takes some input and then when I submit that input on click, the submit-on-click function will set a useState hook to true ( setBoolInput(true) ), then in my App.js file, will ...
0
votes
1
answer
2k
views
Argument of type 'unknown' is not assignable to parameter of type 'SetStateAction<string>'
I've got a useState variable that's grabbing the value from a select input, and conditionally rendering a text component based on that. i.e, if they select other in the select input, a text input for ...
0
votes
1
answer
45
views
conditional rendering not acting uniformly in reactjs?
I have used conditional rendering in the past but for some reason, it's working on one element here but not on another although they are both using the same JSON phrasing and the same type of ...
1
vote
1
answer
643
views
Conditional Rendering,use-timeout Invalid hook call React
When check is true I want to display Next button.I get errors like unexpected token,invalid hook call.
Please help me.Thanks in advance.
import React from "react";
import useTimeout from "use-timeout"...
1
vote
1
answer
3k
views
State update doesn't trigger rerender in conditional rendering component
My component roughly looks like this:
import useCustomHook from "./hooks";
const Test = () => {
const [data, setData] = useCustomHook("example-key", {ready: false});
return (
data....
22
votes
2
answers
25k
views
React JS: How to animate conditionally rendered components?
Example is a functional component in which I am rendering a div conditionally. I want this div to fade-in when rendered conditionally and fade-out vice versa.
For that, I have maintained two local ...
3
votes
1
answer
2k
views
How to write a test for conditional rendering component depended on useState hook in React?
I'm trying to write a test for my functional component, but don't understand how to mock isRoomsLoaded to be true, so I could properly test my UI. How and what do I need to mock?
import React, { ...
1
vote
2
answers
1k
views
React-Hook conditional rendering (no error, but don't work)
I have have no error in my code. But my condition, finally don't work.
const togglePeronsHandler = () => {
const doesShow = personsState.showPersons;
personsState.showPersons = !doesShow;...