Skip to content

Instantly share code, notes, and snippets.

@esr360
Last active August 17, 2019 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esr360/12e8005ab8e44ee2a28e9b6853d1f81d to your computer and use it in GitHub Desktop.
Save esr360/12e8005ab8e44ee2a28e9b6853d1f81d to your computer and use it in GitHub Desktop.
import React, { useState, useContext } from 'react';
import someContextObject from '../someContext';
const useStyles = ({ props, state, context }) => ({
...
});
const MyComponent = (props) => {
const [isActive, setActive] = useState(false);
const context = useContext(someContextObject);
const styles = useStyles({ props, context, state: { isActive } });
return (
<div style={styles} onClick={() => setActive(!isActive)}>
<div style={styles.heading}>{props.heading}</div>
<div style={styles.content}>{props.children}</div>
</div>
)
}
export default MyComponent;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment