React-native: React Native with Context Api Bug

Created on 4 Apr 2018  Â·  14Comments  Â·  Source: facebook/react-native

Maybe there is a bug in line 9402 and 8623 of the file ReactNativeRenderer-dev.js, and the function is popProvider() and updateContextProvider() when I use Context Api in my react-native-app which package.json is like this
{ "name": "cnBlogs", "version": "0.0.1", "private": true, "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "test": "jest" }, "dependencies": { "html-entities": "^1.2.1", "prop-types": "^15.6.1", "react": "^16.3.0-alpha.1", "react-native": "0.54.4", "react-native-tab-navigator": "^0.3.4", "react-native-xml2js": "^1.0.3", "react-navigation": "^1.5.9" }, "devDependencies": { "babel-jest": "22.4.3", "babel-preset-react-native": "4.0.0", "jest": "22.4.3", "react-test-renderer": "^16.3.0-alpha.1" }, "jest": { "preset": "react-native" } }

Ran Commands Locked

Most helpful comment

This issue is solved in react-native 0.55.1 and react 16.3.1,and my package.json is like this
{ "name": "cnBlogs", "version": "0.0.1", "private": true, "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "test": "jest" }, "dependencies": { "html-entities": "^1.2.1", "prop-types": "^15.6.1", "react": "16.3.1", "react-native": "0.55.1", "react-native-android-navigation": "^1.0.4", "react-native-render-html": "^3.9.3", "react-native-tab-navigator": "^0.3.4", "react-native-xml2js": "^1.0.3", "react-navigation": "^1.5.9" }, "devDependencies": { "babel-jest": "22.4.3", "babel-preset-react-native": "4.0.0", "jest": "22.4.3", "react-test-renderer": "^16.3.0-alpha.1" }, "jest": { "preset": "react-native" } }

All 14 comments

the same as "react-native": "0.55.0"

I think it should be var context = providerType._context; instead of var context = providerType.context; in line 9402


Thanks for posting this! It looks like your issue may be incomplete. Are all the fields required by the Issue Template filled out?

If you believe your issue contains all the relevant information, let us know in order to have a maintainer remove the No Template label. Thank you for your contributions.

How to Contribute • What to Expect from Maintainers

Environment

Scanning folders for symlinks in /documents/ReactNative/cnBlogs/node_modules (7ms)

Environment:
  OS: Linux 3.16
  Node: 7.7.0
  Yarn: 0.21.3
  npm: 4.1.2
  Watchman: Not Found
  Xcode: N/A
  Android Studio: Not Found

Packages: (wanted => installed)
  react: ^16.3.0-alpha.1 => 16.3.1
  react-native: 0.54.4 => 0.54.4

Steps to Reproduce

https://reactjs.org/docs/context.html#when-to-use-context
I run official Context Api instance,of course, by react native code

Got the same (similiar?) issue:

Steps to Reproduce

package.json:

{
  "name": "testproject",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "react": "^16.3.1",
    "react-native": "0.54.4"
  },
  "devDependencies": {
    "babel-jest": "22.4.3",
    "babel-preset-react-native": "4.0.0",
    "jest": "22.4.3",
    "react-test-renderer": "^16.3.1"
  },
  "jest": {
    "preset": "react-native"
  }
}

app.js:

import React from "react";
import { Text } from "react-native";

const { Provider, Consumer } = React.createContext("abc");

class App extends React.Component {
  render() {
    return (
      <Provider value={"abc"}>
        <Text>TEST</Text>
      </Provider>
    );
  }
}

export default App;

Environment

Environment:
  OS: macOS High Sierra 10.13.3
  Node: 9.8.0
  Yarn: 1.5.1
  npm: 5.6.0
  Watchman: 4.9.0
  Xcode: Xcode 9.2 Build version 9C40b
  Android Studio: 3.1 AI-173.4670197

Packages: (wanted => installed)
  react: ^16.3.1 => 16.3.1
  react-native: 0.54.4 => 0.54.4

Expected Behavior

It just werks.

Actual Behavior

undefined is not an object (evaluating 'context._currentValue = currentValue')
...

The Issue above from @effectivecui is actually a different bug in react (not react-native) I think. Try to use the latest react version (they updated the test renderer).
The Issue I posted works in react, but not in react-native.

This issue is solved in react-native 0.55.1 and react 16.3.1,and my package.json is like this
{ "name": "cnBlogs", "version": "0.0.1", "private": true, "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "test": "jest" }, "dependencies": { "html-entities": "^1.2.1", "prop-types": "^15.6.1", "react": "16.3.1", "react-native": "0.55.1", "react-native-android-navigation": "^1.0.4", "react-native-render-html": "^3.9.3", "react-native-tab-navigator": "^0.3.4", "react-native-xml2js": "^1.0.3", "react-navigation": "^1.5.9" }, "devDependencies": { "babel-jest": "22.4.3", "babel-preset-react-native": "4.0.0", "jest": "22.4.3", "react-test-renderer": "^16.3.0-alpha.1" }, "jest": { "preset": "react-native" } }

Are React 16.3.1 and RN 0.53 compatible with the new context API?

@Gregoirevda
I think is No. Cause I just struggled with React 16.3.1 and RN 0.54. I am going to update to RN 0.55.1. Good luck.

I figured out I need RN 0.54.0 to use React ^16.3.0

The upgrade from 0.53.3 to 0.54.0 didn't worked out for me. The Blob changes seems to not be handled in the upgrade...

Hey guys, I'm facing the same problem over here:

1) package.json

"react": "^16.3.1",
"react-dom": "^16.3.1",
"react-native": "^0.55.2",
"react-native-web": "^0.5.4",

2) context.js

import React from 'react'

export const TeamSelectedContext = React.createContext()

3) app.js

... all imports
import TeamSelectedContext from './src/context/'

<TeamSelectedContext.Provider value={this.state.team}>
// 
</TeamSelectedContext.Provider>

4) error

Cannot read property 'Provider' of undefined

I also took a good look at Blob and saw no change :'(

Looks like it's working with RN 0.55.3 and React 16.3.2.

I confirm that it's working with RN 0.55.3 and React 16.3.2.

This issue was marked as lacking information required by the issue template. There has been no activity on this issue for a while, so I will go ahead and close it.

If you found this thread after encountering the same issue in the latest release, please feel free to create a new issue with up-to-date information by clicking here.

If you are the author of this issue and you believe this issue was closed in error (i.e. you have edited your issue to ensure it meets the template requirements), please let us know.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

josev55 picture josev55  Â·  3Comments

oney picture oney  Â·  3Comments

phongyewtong picture phongyewtong  Â·  3Comments

janmonschke picture janmonschke  Â·  3Comments

despairblue picture despairblue  Â·  3Comments