score:1
Accepted answer
You need to do ternary
condition to show and hide value:
{show && <button onClick={hideButton} className='btn btn-primary'>Click here</button>}
Full code:
import React, { useState } from "react";
import "./styles.css";
const Parent = () => {
const [show, hide] = useState(true);
const hideButton = () => {
hide(false);
};
return (
<div className="container">
<div className="row">
<div className="col-12">
<div className="one">
{show && (
<button onClick={hideButton} className="btn btn-primary">
Click here
</button>
)}
</div>
</div>
</div>
</div>
);
};
export default function App() {
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
<Parent />
</div>
);
}
Here is the demo: https://codesandbox.io/s/romantic-newton-1wvl1?file=/src/App.js:0-678
Source: stackoverflow.com
Related Query
- How to hide a button when I click the button in react using functional components
- how to change background color when I click the button using react hooks
- How to show a component When I click a button using function components in react
- React - How to pass props down for the .map function when using functional components
- How to change button background color when I click the button in React using Hooks
- How to hide a button when printing using react and styled components?
- How to make one table record editable on button click in React when the table record is mapped?
- How to add a tab dynamically when we click a button using React js and Bootsrap 4
- How to get the time in seconds after click on submit button using React Count Down Timer
- How to hide the offcanvas navbar when selecting the links inside of it using react scroll?
- React Js how to jump whole pages to other pages when click on the navigation button
- how do I render a page in react using functional components when onSubmit?
- How do I access the 'currentImageIdIndex' when using the stack scroll tool in Cornerstone.js in a React functional component?
- How to prevent Re-render in react when the state is changed using Functional Component
- How can strike a post out when i click the complete button in React
- How do I hide a React component on the second click when the component is already open?
- How do I target and change the style of a different element when I click a button in react
- How to disable/enable button when the iput field is empty or filled using state in react js?
- How to increment the old array list key 5 times dynamically when I press the button using React Js?
- When we render react Components from an iterable using Array.prototype.map() how is the index generated, and how does react uses it?
- Deleted all item when click on delete button and how to implement the edit/update functionality using React.js
- How can we upload multiple files using React.JS ? When we click on the upload button all the names of the selected files must appear
- React Conditional Rendering: How can hide the Button when the array "Name" has more than two values?
- how do i toggle the div when click outside of the button in react js?
- how to add a tab dynamically when we click a particular button using react js?
- How to return 'Snake Eyes' or the Values using React Functional Components
- How do I add a transition to my navbar menu in react when I click the toggle button
- How to Reset a form When I click submit Button I React using React hooks
- how do you single select change the value when the radio button is checked, using react hooks?
- How to change the style of a button when it is clicked in react using css?
More Query from same tag
- Convert fetched blob data to object and return it
- Typescript - Shorten code that has repetitive if expressions
- Bootstrap react carousel auto play off
- Is there any way to dynamically add JSON fields in Javascript?
- React component disappears in a blink when using useEffect()
- Why is my render function running before my componentWillMount
- Nested Touchable with absolute position
- How to cast Number or JSON to string when exporting data to excel using React?
- React bind(this, value) in opposite order on function declaration
- TypeError: Cannot read property 'includes' of undefined (React Fetching From Database)
- Generics error with forwardRef: Property 'ref' does not exist on type 'IntrinsicAttributes'
- Updating a variable after ajax call in ReactJS?
- React js paste a previously copied text by clicking on a button
- Not getting updated state from redux store when the state is update
- Parsing json array into an array of maps in react using Lodash
- I want to be redirected to a file.js after when i am logged in
- Radio buttons with react-hook-form validation
- react scroll with styled component is not working
- React-leaflet: how to update marker positions?
- What actually happens when React component returns?
- How to handle popup state in redux?
- Use inherticed functions from a class in functional components
- HTML/JSX forms in React display as [object Object] instead of actual value in array
- react-router-redux - syncHistoryWithStore seems to be missing
- Close self-closing HTML tags on save in VS Code?
- 'TypeError: zmq.zmqVersion is not a function' received when including ZeroMQ JS binding
- Error: No QueryClient set, use QueryClientProvider to set one ,But i did
- How do i fix items not being shown on screen from mongo db?
- React/Redux - Rest operator not working as expected
- Webpack seems to be reloading my component twice with no apparent reason