Skip to content

Instantly share code, notes, and snippets.

@sergiodxa
Created August 9, 2020 01:12
Show Gist options
  • Save sergiodxa/b7f768e56166e11515019910c2fde5b7 to your computer and use it in GitHub Desktop.
Save sergiodxa/b7f768e56166e11515019910c2fde5b7 to your computer and use it in GitHub Desktop.
How do I organize React components internally
function MyComponent(props) {
// refs
const $item = React.useRef();
// states
const [value, setValue] = React.useState("");
// computed
const filtered = React.useMemo(
() => props.list.filter((item) => item.includes(value)),
[props.list, value]
);
// queries
const { data } = useCurrentUser();
// mutations
const [mutateList, { status }] = useMutateList();
// callback
const handleChange = React.useCallback(
function handleChange(event) {
setValue(event.target.value);
},
[setValue]
);
// effects
React.useEffect(() => {
analytics.track({ filter: value, results: filtered });
}, [value, filtered]);
// render
if (filtered.length === 0) return <EmptyUI />;
return <ListUI list={filtered} />;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment