Skip to content

Commit

Permalink
Remove Proxy from React.Context example
Browse files Browse the repository at this point in the history
Hermes doesn't support Proxy ¯\_(ツ)_/¯
  • Loading branch information
guyca committed Aug 21, 2019
1 parent 0e720b6 commit a003f75
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
21 changes: 10 additions & 11 deletions playground/src/context/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
const React = require('react');
let ctx = {
const _context = {
title: 'Title from global context',
count: 0
};

const stateAwareContext = (component) =>
new Proxy(ctx, {
set: function (obj, prop, value) {
obj[prop] = value;
component.setState({ context: stateAwareContext(component) });
return true;
}
});
const contextWrapper = (component) => ({
..._context,
incrementCount: () => {
_context.count++;
component.setState({ context: contextWrapper(component) })
}
});

const GlobalContext = React.createContext({});
class ContextProvider extends React.Component {
state = {context :stateAwareContext(this)};
state = { context: contextWrapper(this) }

render() {
return (
<GlobalContext.Provider value={this.state.context}>
Expand Down
2 changes: 1 addition & 1 deletion playground/src/screens/ContextScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ContextScreen extends React.Component {
{ctx => <Text style={styles.text}>Provider value: {ctx.title}</Text>}
</GlobalContext.Consumer>
<GlobalContext.Consumer>
{ctx => <Button title={`clicked ${ctx.count}`} onPress={() => ctx.count++} />}
{ctx => <Button title={`clicked ${ctx.count}`} onPress={() => ctx.incrementCount()} />}
</GlobalContext.Consumer>
</Root>
);
Expand Down

0 comments on commit a003f75

Please sign in to comment.