Skip to content

Instantly share code, notes, and snippets.

@EmmanuelObua
Last active August 23, 2023 12:41
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 EmmanuelObua/c78e5139fb90b54975dbd169d37dda84 to your computer and use it in GitHub Desktop.
Save EmmanuelObua/c78e5139fb90b54975dbd169d37dda84 to your computer and use it in GitHub Desktop.
import React, { useContext } from 'react';
import { TaskConsumer } from './TaskContext';
// This is a custom hook, a pattern where a reusable function is created that encapsulates common logic or state management,
// allowing the logic to be easily shared between components.
// It's as a higher-order component,a pattern where a component is wrapped in another component,
// allowing the inner component to inherit functionality from the outer component.
export function withTaskContext(Component) {
return function WrappedComponent(props) {
return (
<TaskConsumer>
{taskContext => <Component {...props} taskContext={taskContext} />}
</TaskConsumer>
);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment