Skip to content

Instantly share code, notes, and snippets.

View egor-xyz's full-sized avatar
:octocat:

Egor Stronhin egor-xyz

:octocat:
View GitHub Profile
@egor-xyz
egor-xyz / AllProviders.tsx
Last active July 25, 2022 13:25
Medium. How to combine providers in React
type Providers = [ComponentType<any>, ComponentProps<any>?][];
const combineProviders = (providers: Providers): FC => providers.reduce(
(AccumulatedProviders, [Provider, props = {}]) => ({ children }) => (
<AccumulatedProviders>
<Provider {...props}>
<>{children}</>
</Provider>
</AccumulatedProviders>
),
@egor-xyz
egor-xyz / AnotherComponent.tsx
Last active July 24, 2022 18:56
Medium. Custom react hooks with JSX
import { useCallback, useState } from "react";
import { SmallModal } from "./components/SmallModal";
export const AnotherComponent = () => {
// same code again
const [isOpen, setIsOpen] = useState(false);
// same code again
const toggleOpen = useCallback(() => {
setIsOpen((isOpen) => !isOpen);

Keybase proof

I hereby claim:

  • I am egor-xyz on github.
  • I am egor_xyz (https://keybase.io/egor_xyz) on keybase.
  • I have a public key ASBa0wjfVWsJlhtuoAKgWqQGmsWigZ7QxtJSL13j_9t2uAo

To claim this, I am signing this object: