Update Next.js guide to have explicitly nullable useRef type argument (#3053)

* Update nextjs.md with nullable `storeRef`

* Update other example in nextjs.md

* Apply suggestions from code review

---------

Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>
This commit is contained in:
Mathilda Grace 2025-03-14 19:19:59 -04:00 committed by GitHub
parent 3089fdc435
commit 90f8d592d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -124,8 +124,8 @@ export interface CounterStoreProviderProps {
export const CounterStoreProvider = ({
children,
}: CounterStoreProviderProps) => {
const storeRef = useRef<CounterStoreApi>(null)
if (!storeRef.current) {
const storeRef = useRef<CounterStoreApi | null>(null)
if (storeRef.current === null) {
storeRef.current = createCounterStore()
}
@ -217,8 +217,8 @@ export interface CounterStoreProviderProps {
export const CounterStoreProvider = ({
children,
}: CounterStoreProviderProps) => {
const storeRef = useRef<CounterStoreApi>(null)
if (!storeRef.current) {
const storeRef = useRef<CounterStoreApi | null>(null)
if (storeRef.current === null) {
storeRef.current = createCounterStore(initCounterStore())
}