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 useApp from './useApp' | |
import './styles.css' | |
const Input = (props) => ( | |
<input | |
type="file" | |
accept="image/*" | |
name="img-loader-input" | |
multiple |
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
const triggerInput = (e) => { | |
e.persist() | |
inputRef.current.click() | |
} |
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
return { | |
...state, | |
onSubmit, | |
onChange, | |
triggerInput, | |
} |
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
const useApp = ({ urls }) => { | |
const [results, setResults] = React.useState(null) | |
const promises = urls.map((url) => axios.get(url)) | |
React.useEffect(() => { | |
Promise.all(promises).then(setResults) | |
}, []) | |
return { results } |
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
const promises = React.useMemo(() => { | |
return urls.map((url) => axios.get(url)) | |
}, [urls]) |
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' | |
const UserContext = React.createContext({ | |
user: { | |
firstName: 'Kelly', | |
email: '[email protected]', | |
}, | |
activated: true, | |
}) |
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
const authReducer = (state, action) => { | |
switch (action.type) { | |
case 'set-authenticated': | |
return { ...state, authenticated: action.authenticated } | |
default: | |
return state | |
} | |
} | |
export default authReducer |
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
function combineWords(word) { | |
return function(anotherWord) { | |
return function(andAnotherWord) { | |
return `${word} ${anotherWord} ${andAnotherWord}` | |
} | |
} | |
} |
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
const result = combineWords('hello,')('good')('morning') | |
console.log(result) | |
// result: 'hello, good morning' |
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
let greet = combineWords('wow!') | |
greet = greet('nice') | |
console.log(greet('jacket')) | |
console.log(greet('shoes')) | |
console.log(greet('eyes')) | |
console.log(greet('socks')) | |
console.log(greet('hat')) | |
console.log(greet('glasses')) | |
console.log(greet('finger nails')) |
OlderNewer