General/random internal cleanup (part 1) (#1484)
* sort React imports * improve type signature of the `useEvent` hook * use more correct `useIsoMorphicEffect` check in `useEvent` * refactor `useCallback` to cleaner `useEvent` * convert `const` to `let` Just for consistency.. * cleanup `Tabs` code Created explicit functions that can be called from child components instead of calling `dispatch` directly. Introduced a `useData` and `useActions` hook to make child components easier. The seperation of `useData` allows us to pass down props directly instead of going via the `useReducer` hook and dispatching actions to make values up to date. * cleanup `Combobox` code * cleanup `RadioGroup` code
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import React, {
|
||||
createContext,
|
||||
useCallback,
|
||||
useContext,
|
||||
|
||||
// Types
|
||||
@@ -8,6 +7,7 @@ import React, {
|
||||
ReactNode,
|
||||
} from 'react'
|
||||
import { useIsoMorphicEffect } from '../hooks/use-iso-morphic-effect'
|
||||
import { useEvent } from '../hooks/use-event'
|
||||
|
||||
type OnUpdate = (
|
||||
message: StackMessage,
|
||||
@@ -40,16 +40,13 @@ export function StackProvider({
|
||||
}) {
|
||||
let parentUpdate = useStackContext()
|
||||
|
||||
let notify = useCallback(
|
||||
(...args: Parameters<OnUpdate>) => {
|
||||
// Notify our layer
|
||||
onUpdate?.(...args)
|
||||
let notify = useEvent((...args: Parameters<OnUpdate>) => {
|
||||
// Notify our layer
|
||||
onUpdate?.(...args)
|
||||
|
||||
// Notify the parent
|
||||
parentUpdate(...args)
|
||||
},
|
||||
[parentUpdate, onUpdate]
|
||||
)
|
||||
// Notify the parent
|
||||
parentUpdate(...args)
|
||||
})
|
||||
|
||||
useIsoMorphicEffect(() => {
|
||||
notify(StackMessage.Add, type, element)
|
||||
|
||||
Reference in New Issue
Block a user