당장 개발할 때 알아두면 좋은 리액트 지식들 #1
- Web
- 개발
export default function Profile() {
return (
<img
src="https://i.imgur.com/MK3eW3Am.jpg"
alt="Katherine Johnson"
/>
)
}export default function Gallery() {
return (
<section>
<h1>Amazing scientists</h1>
<Profile />
<Profile />
<Profile />
</section>
);
}<>
<h1>Hedy Lamarr's Todos</h1>
<img
src="https://i.imgur.com/yXOvdOSs.jpg"
alt="Hedy Lamarr"
class="photo"
/>
<ul>
...
</ul>
</>export default function TodoList() {
const name = 'Gregorio Y. Zara';
return (
<h1>{name}'s To Do List</h1>
);
}const today = new Date();
function formatDate(date) {
return new Intl.DateTimeFormat(
'en-US',
{ weekday: 'long' }
).format(date);
}
export default function TodoList() {
return (
<h1>To Do List for {formatDate(today)}</h1>
);
}import { useState } from 'react';
import { sculptureList } from './data.js';
export default function Gallery() {
const [index, setIndex] = useState(0);
// index는 변수, setIndex는 함수
function handleClick() {
// setState와 비슷하쥬?
setIndex(index + 1);
}
// 이제 jsx에서 handleClick 함수를 실행하면 재렌더링됨
let sculpture = sculptureList[index];
return (
<>
<button onClick={handleClick}>
Next
</button>
<h2>
<i>{sculpture.name} </i>
by {sculpture.artist}
</h2>
<h3>
({index + 1} of {sculptureList.length})
</h3>
<img
src={sculpture.url}
alt={sculpture.alt}
/>
<p>
{sculpture.description}
</p>
</>
);
}
// Button.js (함수를 정의한 파일)
// 이렇게 작성해 내보냄
export default function Button() {};
// 함수를 불러와 사용할 다른 파일
// 원하는 이름을 맘대로 지어 불러옴
import Button from './Button.js';
// 다른 파일에선 다른 이름으로 사용할 수 있겠쥐요
import CustomButton from './Button.js';
// 코드에서 사용할 땐 임포트 한 이름으로 쓰면 됨// Button.js
export function Button() {};
// 임포트할 파일
import { Button } from './Button.js';

