-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create a simple checkbox using useState, input and onChange
- Loading branch information
1 parent
799b4f7
commit d39b1f4
Showing
5 changed files
with
18 additions
and
22 deletions.
There are no files selected for viewing
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,26 @@ | ||
import React, {useState} from 'react'; //useState is a function, this is why i use { } | ||
import ReactDOM from 'react-dom'; | ||
import './index.css'; | ||
import React, { useState } from "react"; //useState is a function, this is why i use { } | ||
import ReactDOM from "react-dom"; | ||
import "./index.css"; | ||
|
||
function App() { | ||
//state function | ||
const [status, setStatus] = useState("open");//a function to change the state | ||
|
||
//state variable | ||
/* const [status] = useState("open") //the current state | ||
console.log(status) // open */ | ||
|
||
//what is useState? | ||
/* const result = useState; | ||
console.log(result) // a array with 2 itens - 0:undefined 1:()=> - a fuction */ | ||
const [check, setCheck] = useState(false); | ||
return ( | ||
<> | ||
<h1>the door is:{status}</h1> | ||
<button onClick={()=> setStatus("close")}>Close</button> | ||
</> | ||
<div> | ||
<input | ||
type="checkbox" | ||
value={check} | ||
onChange={() => { | ||
setCheck((check) => !check); | ||
}} | ||
/> | ||
<p>{check ? "checked" : "no checked"}</p> | ||
</div> | ||
); | ||
} | ||
|
||
ReactDOM.render( | ||
<React.StrictMode> | ||
<App name="jess"/> | ||
<App name="jess" /> | ||
</React.StrictMode>, | ||
document.getElementById('root') | ||
document.getElementById("root") | ||
); | ||
|