Skip to content

Commit

Permalink
incorporate use state
Browse files Browse the repository at this point in the history
  • Loading branch information
jessilyneh committed Feb 25, 2022
1 parent 94e5c1b commit 7e0a209
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 28 deletions.
26 changes: 0 additions & 26 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
import './App.css';

// array destructuring

//access third element using destructuring
/* const [,,third] = ["jess","sapato","pé"]
console.log(third) // pé */

// access first element by position using destructuring
/* const [first] = ["jess","sapato","pé"]
console.log(first) //jess */

//access by position
/* const names = ["jess","sapato","pé"]
console.log(names[0]) //jess */

// object destructuring

// using destructuring props
function App({name}) {
return (
<div className="App">
Expand All @@ -25,13 +8,4 @@ function App({name}) {
);
}

// using props
/* function App(props) {
return (
<div className="App">
<h1>Hello,{props.name}</h1>
</div>
);
} */

export default App;
22 changes: 20 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
import React from 'react';
import React, {useState} from 'react'; //useState is a function, this is why i use { }
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';

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 */
return (
<>
<h1>the door is:{status}</h1>
<button onClick={()=> setStatus("close")}>Close</button>
</>
);
}

ReactDOM.render(
<React.StrictMode>
Expand Down

0 comments on commit 7e0a209

Please sign in to comment.