Skip to content

Commit

Permalink
create a simple checkbox using useState, input and onChange
Browse files Browse the repository at this point in the history
  • Loading branch information
jessilyneh committed Feb 28, 2022
1 parent 799b4f7 commit d39b1f4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 22 deletions.
Binary file modified public/favicon.ico
Binary file not shown.
Binary file modified public/logo192.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/logo512.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import './App.css';
import "./App.css";

function App({name}) {
function App({ name }) {
return (
<div className="App">
<h1>Hello,{name}</h1>
Expand Down
36 changes: 16 additions & 20 deletions src/index.js
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")
);

0 comments on commit d39b1f4

Please sign in to comment.