Study/React

Variables in JSX

더 멋진 세상을 꿈꾸는 개발자 2020. 5. 25. 17:59

Variables in JSX

When you inject JavaScript into JSX, that JavaScript is part of the same environment as the rest of the JavaScript in your file.

That means that you can access variables while inside of a JSX expression, even if those variables were declared on the outside.

// Declare a variable:
const name = 'Gerdo';

// Access your variable 
// from inside of a JSX expression:
const greeting = <p>Hello, {name}!</p>;

 

JSX에서의 변수

 

당신이 JSX로 JS를 넣을 때, 그 JavaScript는 파일에 있는 JavaScript의 나머지 부분과 동일한 환경의 일부가 된다.

즉, JSX 표현식 내에서 변수에 액세스할 수 있다는 것을 의미하며, 그러한 변수가 외부에 선언된 경우에도 변수에 액세스할 수 있다.

// Declare a variable:
const name = 'Gerdo';

// Access your variable 
// from inside of a JSX expression:
const greeting = <p>Hello, {name}!</p>;

 


 

 

https://www.codecademy.com/courses/react-101/lessons/react-jsx-advanced/exercises/jsx-variables

 

| Codecademy

Codecademy is the easiest way to learn how to code. It's interactive, fun, and you can do it with your friends.

www.codecademy.com