Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install mobx-react peer dependency error on react v18.0.0 #3363

Closed
SkyVan1eM opened this issue Apr 9, 2022 · 7 comments · Fixed by #3387 or #3386
Closed

Install mobx-react peer dependency error on react v18.0.0 #3363

SkyVan1eM opened this issue Apr 9, 2022 · 7 comments · Fixed by #3387 or #3386
Labels

Comments

@SkyVan1eM
Copy link

Intended outcome:

install mobx-react without any react peer dependency

Actual outcome:

when installing mobx-react , "could not resolve dependency" and searching for react 16 || 17

How to reproduce the issue:

install react app, and it install react 18, and when try to install mobx-react

Versions

react@18.0.0

@mweststrate
Copy link
Member

mweststrate commented Apr 9, 2022 via email

@slezhov
Copy link

slezhov commented Apr 14, 2022

try to use
npm install mobx-react --force

@xaviergonz
Copy link
Contributor

I recently updated mobx-react-component to support react 18.

@FredyC
Since part of its code matches mobx-react-lite some of the changes I had to made might apply to support react 18.

The most important change was to change useForceUpdate to use useSyncExternalStore

import { useSyncExternalStore } from "use-sync-external-store/shim"

function useForceUpdate() {
    type OnStoreChange = () => void

    const stateObjRef = useRef([])

    const getStateObj = useCallback(() => stateObjRef.current, [])

    const onStoreChangeRef = useRef<OnStoreChange | undefined>()

    const updateStateObj = useCallback(() => {
        stateObjRef.current = []
        onStoreChangeRef.current?.()
    }, [])

    const subscribe = useCallback((onStoreChange: OnStoreChange) => {
        onStoreChangeRef.current = onStoreChange

        return () => {
            onStoreChangeRef.current = undefined
        }
    }, [])

    useSyncExternalStore(subscribe, getStateObj)

    return updateStateObj
}

Also I had to change some tests that used fake timers to use real ones or they wouldn't pass (still looking into it), added some missing "act" calls and removed some tests that relied on using the real react render instead of the testing library render.

Here are all the changes:

xaviergonz/mobx-react-component@0e4c330...master

@blackrabbit99
Copy link

@mweststrate do you have any plans or estimate to support React@18 for mobx-react ?

@mweststrate
Copy link
Member

mweststrate commented Apr 25, 2022 via email

@abhi-go
Copy link

abhi-go commented May 4, 2022

Thanks Michael! Looking forward to trying out MST/Mobx-react with React 18.

@mweststrate
Copy link
Member

Should be fixed in mobx-react-lite@3.4.0 / mobx-react@7.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants