-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixed stale / wrong states when initializing; Backported from ma…
…ster; This version was not affected by the bug but just all versions have the same behaviour now.
- Loading branch information
Showing
7 changed files
with
106 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { pm } from '../lib/utils' | ||
import { serializers } from '../lib/serializers' | ||
import { factoryParameters } from '../lib/store' | ||
import React, { createContext, FC, useContext, useMemo } from 'react' | ||
|
||
const config = { | ||
someParameter: pm('wow', serializers.string) | ||
} | ||
const defaultValues = () => ({ | ||
someParameter: 'test' | ||
}) | ||
|
||
interface Props<T = {}> { | ||
readonly defaultValues: T | ||
} | ||
|
||
const defaultProductSearchWithoutCustomization = factoryParameters( | ||
config, | ||
defaultValues, | ||
'some' | ||
) | ||
|
||
const ConfigurableProductSearchContext = createContext( | ||
defaultProductSearchWithoutCustomization | ||
) | ||
|
||
export const SearchProvider: FC<Props> = ({ | ||
defaultValues: thisDefaultValues, | ||
children | ||
}) => { | ||
const value = useMemo(() => { | ||
return factoryParameters( | ||
config, | ||
() => ({ | ||
...defaultValues(), | ||
...thisDefaultValues | ||
}), | ||
'some' | ||
) | ||
}, [thisDefaultValues]) | ||
|
||
return ( | ||
<ConfigurableProductSearchContext.Provider value={value}> | ||
{children} | ||
</ConfigurableProductSearchContext.Provider> | ||
) | ||
} | ||
|
||
export const useQuery = () => { | ||
const { useQuery: thisUseQuery } = useContext( | ||
ConfigurableProductSearchContext | ||
) | ||
return thisUseQuery() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters