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

Context Api pass as props return undefined #19704

Closed
alz10 opened this issue Jun 14, 2018 · 2 comments
Closed

Context Api pass as props return undefined #19704

alz10 opened this issue Jun 14, 2018 · 2 comments
Labels
Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@alz10
Copy link

alz10 commented Jun 14, 2018

Environment

OS: Windows 10
Node: 8.11.1
Yarn: Not Found
npm: 6.1.0
Watchman: Not Found
Xcode: N/A
Android Studio: Version  3.1.0.0 AI-173.4720617

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

Description

I'm using context api and wanted to access context outside the render() function for example in a life cycle method componentDidMount().

Steps to Reproduce

I tried to use this tutorial https://reactjs.org/docs/context.html#accessing-context-in-lifecycle-methods. I passed down the context to a props but it gave undefined when i console log this.props.context

Expected Behavior

Access context outside render()

Actual Behavior

const contextToProps = () => (
  <AppConsumer>{context => <TestComponent context={context} />}</AppConsumer>
);

class TestComponent extends PureComponent {
  componentDidMount() {
    console.log(this.props.context); //Underfined
  }
     render() {
       return()
   }
}

Am i doing it correctly?

@stale
Copy link

stale bot commented Sep 12, 2018

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Sep 12, 2018
@stale
Copy link

stale bot commented Sep 19, 2018

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Sep 19, 2018
@facebook facebook locked as resolved and limited conversation to collaborators Sep 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

1 participant