Created
March 22, 2019 02:21
-
-
Save dantman/68ebdd1c1ebb9514064a5914dfd955be to your computer and use it in GitHub Desktop.
React context slice idea
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
MyContext.slice(value => value.foo); | |
const KeyContext = useMemo(() => MyContext.slice(value => value[key]), [key]) | |
const keyValue = useContext(KeyContext); | |
const KeyContext = useMemo(() => MyContext.slice(value => value[key]), [key]) | |
return <KeyContext.Consumer>{keyValue => keyValue}</KeyContext.Consumer> | |
@decorate(memoizeOne) | |
getKeyContext(key) { | |
return MyContext.slice(value => value[key]); | |
} | |
render() { | |
const {key} = this.props; | |
const KeyContext = this.getKeyContext(); | |
return <KeyContext.Consumer>{keyValue => keyValue}</KeyContext.Consumer>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment