Create codemod for addressing ESLint warnings (#10032)
This commit is contained in:
@@ -1,25 +1,29 @@
|
||||
import React from 'react'
|
||||
import {
|
||||
createContext,
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useState,
|
||||
} from 'react'
|
||||
|
||||
import * as persisted from '#/state/persisted'
|
||||
|
||||
type StateContext = persisted.Schema['largeAltBadgeEnabled']
|
||||
type SetContext = (v: persisted.Schema['largeAltBadgeEnabled']) => void
|
||||
|
||||
const stateContext = React.createContext<StateContext>(
|
||||
const stateContext = createContext<StateContext>(
|
||||
persisted.defaults.largeAltBadgeEnabled,
|
||||
)
|
||||
stateContext.displayName = 'LargeAltBadgeStateContext'
|
||||
const setContext = React.createContext<SetContext>(
|
||||
const setContext = createContext<SetContext>(
|
||||
(_: persisted.Schema['largeAltBadgeEnabled']) => {},
|
||||
)
|
||||
setContext.displayName = 'LargeAltBadgeSetContext'
|
||||
|
||||
export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
const [state, setState] = React.useState(
|
||||
persisted.get('largeAltBadgeEnabled'),
|
||||
)
|
||||
const [state, setState] = useState(persisted.get('largeAltBadgeEnabled'))
|
||||
|
||||
const setStateWrapped = React.useCallback(
|
||||
const setStateWrapped = useCallback(
|
||||
(largeAltBadgeEnabled: persisted.Schema['largeAltBadgeEnabled']) => {
|
||||
setState(largeAltBadgeEnabled)
|
||||
persisted.write('largeAltBadgeEnabled', largeAltBadgeEnabled)
|
||||
@@ -27,7 +31,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
[setState],
|
||||
)
|
||||
|
||||
React.useEffect(() => {
|
||||
useEffect(() => {
|
||||
return persisted.onUpdate(
|
||||
'largeAltBadgeEnabled',
|
||||
nextLargeAltBadgeEnabled => {
|
||||
@@ -46,9 +50,9 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
}
|
||||
|
||||
export function useLargeAltBadgeEnabled() {
|
||||
return React.useContext(stateContext)
|
||||
return useContext(stateContext)
|
||||
}
|
||||
|
||||
export function useSetLargeAltBadgeEnabled() {
|
||||
return React.useContext(setContext)
|
||||
return useContext(setContext)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user