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

In 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?

Hi Amy,

Would you mind providing a link to your code?

3 Answers

Nevermind, I fixed it. I changed the variable declaration to var title; . Sorry for the bother.

Not a bother at all. It’s awesome that you were able to squash this bug on your own.

I am coding in VS Code. I can provide a screenshot of the players array, would that help?

import 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
      }
    ]
  };

OK. 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?