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 trialAmy Hendrix
12,119 PointsIn React what do I use in place of name(deprecated). Changing the variable gave me a no-use-before-defined error.
In the React Components class I am building the scoreboard app.
I received an error stating 'name' is now deprecated.
I tried using title in place of name beginning in the players array and declared a new variable for title but received a ReferenceError: Cannot access 'title' before initialization.
So how do I declare a new variable but do so after initialization?
3 Answers
Amy Hendrix
12,119 PointsNevermind, I fixed it. I changed the variable declaration to var title; . Sorry for the bother.
Brandon White
Full Stack JavaScript Techdegree Graduate 35,771 PointsNot a bother at all. Itβs awesome that you were able to squash this bug on your own.
Amy Hendrix
12,119 PointsI am coding in VS Code. I can provide a screenshot of the players array, would that help?
Amy Hendrix
12,119 Pointsimport React from 'react';
import './App.css';
import Header from './Header';
import Player from './Player';
import AddPlayerForm from './AddPlayerForm';
let title = title;
class App extends React.Component {
state = {
players: [
{
title: "Amy",
score: 0,
id: 1
},
{
title: "John",
score: 0,
id: 2
},
{
title: "Jack",
score: 0,
id: 3
},
{
title: "Forrest",
score:0,
id: 4
}
]
};
Brandon White
Full Stack JavaScript Techdegree Graduate 35,771 PointsOK. What is title supposed to represent here.
In the following line:
let title = title
What are you trying to accomplish with it? What info/Datatype is meant to be on the right side of the assignment operator?
Brandon White
Full Stack JavaScript Techdegree Graduate 35,771 PointsBrandon White
Full Stack JavaScript Techdegree Graduate 35,771 PointsHi Amy,
Would you mind providing a link to your code?