show and hide div based on radio button click react

Solutions on MaxInterview for show and hide div based on radio button click react by the best coders in the world

showing results for - "show and hide div based on radio button click react"
Gianna
15 Jul 2018
1import React from "react";
2
3function Radio () {
4  const [status, setStatus] = React.useState(0) // 0: no show, 1: show yes, 2: show no.
5
6  const radioHandler = (status) => {
7    setStatus(status);
8  };
9
10  return (
11    <>
12      <input type="radio" name="release" checked={status === 1} onClick={(e) => radioHandler(1)} />
13      <input type="radio" name="release" checked={status === 2} onClick={(e) => radioHandler(2)} />
14      {status === 1 && drawYesContent()}
15      {status === 2 && drawNoContent()}
16    </>
17  );
18}
19
20export default Radio;
21