Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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

PREVIOUS NEXT
Code Example
Javascript :: utc to est javascript 
Javascript :: mdn getcurrentposition 
Javascript :: input element change event data 
Javascript :: sequelize date format 
Javascript :: how to add multiple event listener in javascript 
Javascript :: mapbox add a leaflet marker with popup 
Javascript :: get all database react native 
Javascript :: react computed example 
Javascript :: delete node between indexes node list js 
Javascript :: methods of object js 
Javascript :: prevent vscode debugger from entering node module 
Javascript :: ways to open modal in angular 
Javascript :: jest always pass async await 
Javascript :: http request body angular 
Javascript :: Find Dubplicate In Array of Object 
Javascript :: find vowels in string javascript 
Javascript :: mongoose pagination 
Javascript :: routerlink not working 
Javascript :: A better way to concatenate arrays 
Javascript :: convert rgb to hex 
Javascript :: how to create new route in express 
Javascript :: useselector in redux 
Javascript :: auto create a test file in angular 
Javascript :: split js 
Javascript :: hide component vuejs 
Javascript :: read dictionary values 
Javascript :: trigger keydown event javascript 
Javascript :: source code angular material LOGIN PAGE 
Javascript :: js select all 
Javascript :: iterating over a string 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =