Last active
June 23, 2020 01:19
-
-
Save deniztetik/16b6a32d95c3bb573948b62c61ea9dba to your computer and use it in GitHub Desktop.
React-TS-From-Scratch
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
const users = [ | |
{ id: 7, name: "Mumble" }, | |
{ id: 14, name: "Harambe" }, | |
{ id: 33, name: "Nemo" } | |
]; | |
function findUserById(id) { | |
return users.find(user => user.id === id); | |
} | |
const id = "33"; | |
findUserById(id); // undefined |
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
const users = [ | |
{ id: 7, name: "Mumble" }, | |
{ id: 14, name: "Harambe" }, | |
{ id: 33, name: "Nemo" } | |
]; | |
function findUserById(id) { | |
// TS7006: Parameter 'id' implicitly has 'any' type. | |
return users.find(user => user.id === id); | |
} | |
const id = "33"; | |
findUserById(id); // undefined |
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
const users = [ | |
{ id: 7, name: "Mumble" }, | |
{ id: 14, name: "Harambe" }, | |
{ id: 33, name: "Nemo" }, | |
]; | |
function findUserById(id: number) { | |
return users.find((user) => user.id === id); | |
} | |
const id = "33"; | |
findUserById(id); | |
/* | |
TS 2345: | |
Argument of type '"33"' is not assignable | |
to parameter of type 'number'. | |
*/ |
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
const users = [ | |
{ id: 7, name: "Mumble" }, | |
{ id: 14, name: "Harambe" }, | |
{ id: 33, name: "Nemo" }, | |
]; | |
function findUserById(id: number) { | |
return users.find((user) => user.id === id); | |
} | |
const id = "33"; | |
findUserById(parseInt(id)); |
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
function App(props) { | |
return ( | |
<div className="App"> | |
<header className="App-header"> | |
<img src={logo} className="App-logo" alt="logo" /> | |
<p>{props.message}</p> | |
</header> | |
</div> | |
); | |
} |
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
function App(props) { | |
// Parameter 'props' implicitly has an 'any' type. TS7006 | |
return ( | |
<div className="App"> | |
<header className="App-header"> | |
<img src={logo} className="App-logo" alt="logo" /> | |
<p>{props.message}</p> | |
</header> | |
</div> | |
); | |
} |
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
type AppProps = { message: string }; | |
function App(props: AppProps) { | |
// Parameter 'props' implicitly has an 'any' type. TS7006 | |
return ( | |
<div className="App"> | |
<header className="App-header"> | |
<img src={logo} className="App-logo" alt="logo" /> | |
<p>{props.message}</p> | |
</header> | |
</div> | |
); | |
} |
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
type AppProps = { message: string }; | |
type AppState = { count: number }; | |
class App extends Component<AppProps, AppState> { | |
state = { | |
count: 0, | |
}; | |
updateCounter = () => { | |
this.setState({ count: this.state.count + 1 }); | |
}; | |
render() { | |
return ( | |
<div className="App"> | |
<header className="App-header"> | |
<img src={logo} className="App-logo" alt="logo" /> | |
<p>{props.message}</p> | |
</header> | |
</div> | |
); | |
} | |
} |
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
const users = [ | |
{ id: 7, name: "Mumble" }, | |
{ id: 14, name: "Harambe" }, | |
{ id: 33, name: "Nemo" } | |
]; | |
function findUserById(id) { | |
return users.find(user => user.id === id); | |
} | |
const id = 33; | |
findUserById(id); // {id: 33, name: 'Nemo'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment