728x90
반응형

mobx 를 사용하면

 

[mobx-react-lite] 'useObserver(fn)' is deprecated. Use `<Observer>{fn}</Observer>` instead, or wrap the entire component in `observer`. 

 

해당 에러가 나오기 마련이다.

 

import {Observer, useObserver} from 'mobx-react-lite';
import React, {useContext} from 'react';
import {storesContext} from '../utils/context';

export const useStoreData = (context, storeSelector, dataSelector) => {
const value = useContext(context);
if (!value) {
throw new Error('No store');
}
const store = storeSelector(value);

return useObserver(() => {
return dataSelector(store);
});
};

export default dataSelector => {
return useStoreData(storesContext, contextData => contextData, dataSelector);
};

해당 부분을

 

import {Observer, useObserver} from 'mobx-react-lite';
import React, {useContext} from 'react';
import {storesContext} from '../utils/context';

export const useStoreData = (context, storeSelector, dataSelector) => {
const value = useContext(context);
if (!value) {
throw new Error('No store');
}
const store = storeSelector(value);

return (
<Observer>
{() => {
return dataSelector(store);
}}
</Observer>
);
};

export default dataSelector => {
return useStoreData(storesContext, contextData => contextData, dataSelector);
};

로 변경해주면 warning 사라짐

728x90
반응형

+ Recent posts