Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

show and hide div based on radio button click react

import React from "react";

function Radio () {
  const [status, setStatus] = React.useState(0) // 0: no show, 1: show yes, 2: show no.

  const radioHandler = (status) => {
    setStatus(status);
  };

  return (
    <>
      <input type="radio" name="release" checked={status === 1} onClick={(e) => radioHandler(1)} />
      <input type="radio" name="release" checked={status === 2} onClick={(e) => radioHandler(2)} />
      {status === 1 && drawYesContent()}
      {status === 2 && drawNoContent()}
    </>
  );
}

export default Radio;
Comment

PREVIOUS NEXT
Code Example
Javascript :: axios forward 
Javascript :: While resolving: gatsby-starter-ghost@2.0.0 npm ERR! Found: react@17.0.2 
Javascript :: anagram 
Javascript :: javascript createelement innerhtml 
Javascript :: react component will mount new method 
Javascript :: document.getelementbyid 
Javascript :: on reload js 
Javascript :: less than or equal to javascript 
Javascript :: logic operators in js 
Javascript :: post request javascript 
Javascript :: useScroll 
Javascript :: jquery on multiple events 
Javascript :: how to convert string to alternate case in javascript 
Javascript :: angular ionic capacitor nfc reader 
Javascript :: convert nuber into string react js 
Javascript :: how to create a website with javascript 
Javascript :: javascript template literals html 
Javascript :: concat strings shopify liquid 
Javascript :: v-for only getting one first value vuejs 
Javascript :: javascript access ajax response headers 
Javascript :: index of 
Javascript :: javascript date set hours minutes seconds to 0 
Javascript :: js random generator 
Javascript :: moment to date object 
Javascript :: dynamic array in javascript 
Javascript :: pass data to slot vue 
Javascript :: datatable set row id 
Javascript :: stateless vs stateful components in react 
Javascript :: how to insert with variables from js to mysql 
Javascript :: how to get input with name in jest test 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =