Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Create Context

Brandyn Lordi
Brandyn Lordi
17,778 Points

how to log React.createContext() to the console?

at 0:45 Guil logged the value of const ScoreboardContext = React.createContext() to the console. When i log ScoreboardContext to the console, i get an undefined error.

Any idea what I might be missing?

1 Answer

Brandyn Lordi
Brandyn Lordi
17,778 Points

Over a year later i return to this course and came up with the same question only to discover my own unanswered question! I have an answer now for anyone that might be wondering...

Simply add: import {ScoreboardContext} from './context' to app.js

then add: console.log(ScoreboardContext) somewhere in the render function, before the return statement.

Erland Van Olmen
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Erland Van Olmen
Full Stack JavaScript Techdegree Graduate 17,825 Points

For the above to work, you also need to export the ScoreboardContext like so:

import React from 'react';
export const ScoreboardContext = React.createContext();  // added export here
export const Provider = ScoreboardContext.Provider;
export const Consumer = ScoreboardContext.Consumer;