This file contains hidden or 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
First way, object using module.exports | |
module.exports = { | |
sum: function(a,b){ | |
return a + b; | |
}, | |
sub: function(a,b){ | |
return a - b; | |
} | |
This file contains hidden or 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
import React, { useEffect } from 'react'; | |
import { Button } from './Button'; | |
function App() { | |
const [total, setTotal] = React.useState(0); | |
return ( | |
<div> | |
<p>Total: {total}</p> | |
<Button increment={setTotal} /> | |
</div> |
This file contains hidden or 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
import React from 'react'; | |
import { Button } from './Button'; | |
import { Input } from './Input'; | |
import { Checkbox } from './Checkbox'; | |
function App() { | |
const [total, setTotal] = React.useState(0) | |
const [data, setData] = React.useState(''); | |
function increment() { |
This file contains hidden or 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
import React from 'react' | |
export const Checkbox = ({ label} : {label: string}) => { | |
const [value, setValue] = React.useState(false); | |
return ( | |
<label style={{ | |
padding: "1rem", | |
border: value ? "2px solid #8D2" : "2px solid #F70" | |
}}> | |
<input |
This file contains hidden or 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
import React from 'react' | |
export const Checkbox = ({ label} : {label: string}) => { | |
const [value, setValue] = React.useState(false); | |
const handleChange: React.ChangeEventHandler<HTMLInputElement> = (event) => { | |
setValue(event.currentTarget.checked) | |
} | |
return ( | |
<label style={{ | |
padding: "1rem", |