Skip to content

Commit

Permalink
array and object destructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
jessilyneh committed Feb 24, 2022
1 parent f3b589a commit 94e5c1b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
44 changes: 28 additions & 16 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
import logo from './logo.svg';
import './App.css';

function App() {
// 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">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
<h1>Hello,{name}</h1>
</div>
);
}

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

export default App;
7 changes: 1 addition & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@ import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';

ReactDOM.render(
<React.StrictMode>
<App />
<App name="jess"/>
</React.StrictMode>,
document.getElementById('root')
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();

0 comments on commit 94e5c1b

Please sign in to comment.