mirror of
https://github.com/streamich/react-use.git
synced 2026-01-25 14:17:16 +00:00
fix: replace createFactory usages with createElement
This commit is contained in:
parent
af66607dfd
commit
ad29bea7b0
@ -1,11 +1,11 @@
|
||||
import { createFactory, createContext, useContext, useReducer } from 'react';
|
||||
import { createElement, createContext, useContext, useReducer } from 'react';
|
||||
|
||||
const createReducerContext = <R extends React.Reducer<any, any>>(
|
||||
reducer: R,
|
||||
defaultInitialState: React.ReducerState<R>
|
||||
) => {
|
||||
const context = createContext<[React.ReducerState<R>, React.Dispatch<React.ReducerAction<R>>] | undefined>(undefined);
|
||||
const providerFactory = createFactory(context.Provider);
|
||||
const providerFactory = (props, children) => createElement(context.Provider, props, children);
|
||||
|
||||
const ReducerProvider: React.FC<{ initialState?: React.ReducerState<R> }> = ({ children, initialState }) => {
|
||||
const state = useReducer<R>(reducer, initialState !== undefined ? initialState : defaultInitialState);
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { createFactory, createContext, useContext, useState } from 'react';
|
||||
import { createElement, createContext, useContext, useState } from 'react';
|
||||
|
||||
const createStateContext = <T>(defaultInitialValue: T) => {
|
||||
const context = createContext<[T, React.Dispatch<React.SetStateAction<T>>] | undefined>(undefined);
|
||||
const providerFactory = createFactory(context.Provider);
|
||||
const providerFactory = (props, children) => createElement(context.Provider, props, children);
|
||||
|
||||
const StateProvider: React.FC<{ initialValue?: T }> = ({ children, initialValue }) => {
|
||||
const state = useState<T>(initialValue !== undefined ? initialValue : defaultInitialValue);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user