получить предупреждение "componentWillReceiveProps был переименован" после перемещения проекта expo для реагирования на нативный - PullRequest
0 голосов
/ 13 февраля 2020

Я переношу свой выставочный проект, чтобы отреагировать на нативный проект. Я удалил expo, и я попытался использовать собственный способ, чтобы добавить spla sh screen и pu sh уведомления и добавить шрифты без expo. Я также установил реагирующую навигацию с родным способом без экспо. Я запускаю проект, используя android studio и Xcode. У меня есть некоторые проблемы, но я исправил их, исправив некоторые версии пакетов в моем пакете. json file Теперь я получаю эту ошибку:

Warning: componentWillReceiveProps has been renamed, and is not recommended for use. See ... for details.

* Move data fetching code or side effects to componentDidUpdate.
* If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: ***
* Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.

Please update the following components: SafeView

мой старый файл packeges:

    "react": "16.8.3",
    "react-dom": "^16.8.6",
    "react-native": "https://github.com/expo/react-native/archive/sdk- 
     33.0.0.tar.gz",
    "react-native-autocomplete-input": "^4.1.0",
    "react-native-elements": "^1.1.0",
     ....
    "react-navigation": "^4.0.10",
    "react-navigation-drawer": "^2.3.3",
    "react-navigation-material-bottom-tabs": "^1.0.0",
    "react-navigation-stack": "^1.10.3",

My current version use safe area context with react navigation :

    "dependencies": {
    "@react-native-community/async-storage": "^1.7.1",
    "@react-native-community/masked-view": "^0.1.6",
    "@react-native-community/push-notification-ios": "^1.0.6",
    "axios": "^0.19.0",
    "buffer": "^5.4.3",
    "color": "^3.1.2",
    "libphonenumber-js": "^1.7.26",
    "moment": "^2.24.0",
    "native-base": "^2.13.5",
    "native-base-autocomplete": "^1.3.2",
    "querystring": "^0.2.0",
    "react": "16.9.0",
    "react-native": "0.61.5",
    "react-native-elements": "^1.1.0",
    "react-native-event-source": "^1.1.0",
    "react-native-gesture-handler": "^1.5.6",
    "react-native-globalize": "^3.0.0",
    "react-native-material-textfield": "^0.16.1",
    "react-native-modal-selector": "^1.1.1",
    "react-native-paper": "^2.16.0",
    "react-native-push-notification": "^3.1.9",
    "react-native-reanimated": "^1.0.1",
    "react-native-responsive-ui": "^2.1.1",
    "react-native-root-toast": "^3.1.2",
    "react-native-safe-area-context": "^0.7.2",
    "react-native-screens": "^2.0.0-beta.2",
    "react-native-slider": "^0.11.0",
    "react-native-splash-screen": "^3.2.0",
    "react-native-vector-icons": "^6.6.0",
    "react-navigation": "^4.0.10",
    "react-navigation-drawer": "^2.3.3",
    "react-navigation-material-bottom-tabs": "^1.0.0",
    "react-navigation-stack": "^1.10.3",
    "react-redux": "^7.1.0",
    "redux": "^4.0.4",
    "redux-devtools": "^3.5.0",
    "redux-devtools-extension": "^2.13.8",
    "redux-thunk": "^2.3.0",
    "search-params": "^2.1.3",
    "whatwg-url": "^8.0.0"
  },

Ответы [ 2 ]

1 голос
/ 13 февраля 2020

В вашем случае на самом деле это не ошибка. Это предупреждение от собственного ответа.

componentWillReceiveProps - это синхронная перехват. Вызов асинхронной функции, такой как выборка данных внутри этой ловушки, должен будет визуализироваться между установкой новых реквизитов и окончанием загрузки данных.

Таким образом, componentWillReceiveProps считается устаревшим в пользу следующая причина:

  1. Использование componentDidUpdate

Итак, я предлагаю вам использовать хук componentDidUpdate, насколько это возможно, и обновить ваш код.

  • Подобные вещи случаются при сравнении componentWillMount и componentDidMount . Используйте componentDidMount всякий раз, когда вам нужно работать в асинхронном режиме c и забывать componentWillMount при любых условиях.
0 голосов
/ 13 февраля 2020

Я исправляю это предупреждение, переустанавливая навигацию и используемые зависимости, поэтому мои текущие файлы пакетов:

 "@react-native-community/async-storage": "^1.7.1",
"@react-native-community/masked-view": "^0.1.6",
"@react-native-community/push-notification-ios": "^1.0.6",
"axios": "^0.19.0",
"buffer": "^5.4.3",
"color": "^3.1.2",
"libphonenumber-js": "^1.7.26",
"moment": "^2.24.0",
"native-base": "^2.13.5",
"native-base-autocomplete": "^1.3.2",
"querystring": "^0.2.0",
"react": "16.9.0",
"react-native": "0.61.5",
"react-native-elements": "^1.1.0",
"react-native-event-source": "^1.1.0",
"react-native-gesture-handler": "^1.5.6",
"react-native-globalize": "^3.0.0",
"react-native-material-textfield": "^0.16.1",
"react-native-modal-selector": "^1.1.1",
"react-native-paper": "^3.6.0",
"react-native-push-notification": "^3.1.9",
"react-native-reanimated": "^1.7.0",
"react-native-responsive-ui": "^2.1.1",
"react-native-root-toast": "^3.1.2",
"react-native-safe-area-context": "^0.7.3",
"react-native-screens": "^2.0.0-beta.2",
"react-native-slider": "^0.11.0",
"react-native-splash-screen": "^3.2.0",
"react-native-vector-icons": "^6.6.0",
"react-navigation": "^4.1.1",
"react-navigation-drawer": "^2.3.4",
"react-navigation-material-bottom-tabs": "^2.1.5",
"react-navigation-stack": "^2.1.1",
"react-redux": "^7.1.0",
"redux": "^4.0.4",
"redux-devtools": "^3.5.0",
"redux-devtools-extension": "^2.13.8",
"redux-thunk": "^2.3.0",
"search-params": "^2.1.3",
"whatwg-url": "^8.0.0"

спасибо всем

...