反应native-undefined不是一个对象(评估' _reactNative.CookieManager.get')

时间:2017-08-25 12:14:50

标签: react-native

undefined不是对象(评估' _reactNative.CookieManager.get')

undefined is not an object (evaluating '_reactNative.CookieManager.get')

此错误显示在Android模拟器上。 在react.js

    CookieManager.get("http://10.42.0.1:8000/login/", (err, res) => {

      fetch("http://10.42.0.1:8000/login/", {
        method: "POST",
        headers: {
          'Accept': 'application/json',
          'Content-Type': 'application/json',
          'X-CSRFToken': res.csrftoken,
        },
        body: JSON.stringify({
          username: 'user',
          password: 'securepassword',
        })
      })
      .then((response) => response.json())
      .then((responseJson) => {
        console.log(responseJson);
      })
    });
  }

pacakge.json

 "dependencies": {
"babel-preset-react-native": "2.1.0",
"react": "16.0.0-alpha.12",
"react-native": "0.47.1",
"react-native-cookie": "^0.2.0",
"react-navigation": "^1.0.0-beta.11"
  },
"devDependencies": {
"babel-jest": "20.0.3",
"jest": "20.0.4",
"react-test-renderer": "16.0.0-alpha.12"
 },

我一步一步做了什么: -

从npm安装库

npm install react-native-cookie --save

链接原生代码

react-native link react-native-cookie

此处在app.js中导入

import {
 Cookie,
  CookieManager
 } from 'react-native-cookie';

enter image description here

欢迎任何建议..我们很沮丧请帮助摆脱这个!!!

2 个答案:

答案 0 :(得分:2)

使用前请查看包裹的README

没有像CookieManager这样唯一的Cookie。

将CookieManager更改为Cookie。

答案 1 :(得分:0)

为我而改变

import {CookieManager} from '@react-native-community/cookies';

import CookieManager from '@react-native-community/cookies';

解决了这个问题。