Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

hide and show on button click in react js functional component

const [show,setShow]=useState(true)
  return (
    <div className="App">
     {
       show?<h1>Hello World !</h1>:null
     }
      <button onClick={()=>setShow(true)} >Show</button>
     <button onClick={()=>setShow(false)} >Hide</button> 
    </div>
  );
Comment

How to hide component in React

import React, { useState } from 'react';

const Component = () => {
  const [show, setShow] = useState(false);
  return(
    <>
      <button onClick={() => setShow(prev => !prev)}>Click</button>
      {show && <Box>This is your component</Box>}
    </>
  );
}

export default Component
Comment

react hide element

React circa 2020
In the onClick callback, call the state hook's setter function to update the state and re-render:

const Search = () => {
  const [showResults, setShowResults] = React.useState(false)
  const onClick = () => setShowResults(true)
  return (
    <div>
      <input type="submit" value="Search" onClick={onClick} />
      { showResults ? <Results /> : null }
    </div>
  )
}

const Results = () => (
  <div id="results" className="search-results">
    Some Results
  </div>
)

ReactDOM.render(<Search />, document.querySelector("#container"))
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.13.1/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.13.1/umd/react-dom.production.min.js"></script>

<div id="container">
  <!-- This element's contents will be replaced with your component. -->
</div>
Comment

Show and Hide element in react

return(
  <nav className="nav__bar">
    <ul className="menu">
      <li className="menu__icon" onClick={() => setShow(currentShow => !currentShow)}>
        <box-icon name='menu' color="floralwhite" size="md"/>
        { show ? <Curtain/> : null }
      </li>
    </ul>
  </nav>
);
Comment

hide show object in react

const Search = () => {
  const [showResults, setShowResults] = React.useState(false)
  const onClick = () => setShowResults(true)
  return (
    <div>
      <input type="submit" value="Search" onClick={onClick} />
      { showResults ? <Results /> : null }
    </div>
  )
}

const Results = () => (
  <div id="results" className="search-results">
    Some Results
  </div>
)

ReactDOM.render(<Search />, document.querySelector("#container"))
Comment

how to hide a button in react

{ this.state.showMyComponent ? <MyComponent /> : null }

{ this.state.showMyComponent && <MyComponent /> }
Comment

PREVIOUS NEXT
Code Example
Javascript :: two way binding in angular 
Javascript :: how to print reverse number in javascript 
Javascript :: javascript get max value in array of objects 
Javascript :: redirect router v6 
Javascript :: regex country code 
Javascript :: javascript invert binary tree 
Javascript :: get class name of object javascript 
Javascript :: how to define class in javascript 
Javascript :: hello world js 
Javascript :: how to validate multiple input field in javascript 
Javascript :: 2d arrays js 
Javascript :: js replace last occurrence of string 
Javascript :: how to make a discord bot delete messages after time js 
Javascript :: react component pass props 
Javascript :: vs code ouput stack 
Javascript :: nlhoman json load from file 
Javascript :: heroku 
Javascript :: jquery ui sortable between two tables 
Javascript :: JavaScript Constructor Function Parameters 
Javascript :: sign changely api 
Javascript :: javascript Assigning to a new property on a non-extensible object is not allowed 
Javascript :: actionscript fibonacci fibonaccinumbers 
Javascript :: Knockout js custom bindings 
Javascript :: divide array in chunks 
Javascript :: gatsby js quick start 
Javascript :: phaser enable pixel art 
Javascript :: scrolling text animation javascript 
Javascript :: node transitions 
Javascript :: Access models in ExpressJS 
Javascript :: jquery selectors 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =