Mi Lugarcito
React와 Firebase로 앱 개발하기 - Firebase DB 구축 및 React와 연동 본문
Words.js
import React from 'react';
import Card from '@material-ui/core/Card';
import CardContent from '@material-ui/core/CardContent';
import Typography from '@material-ui/core/Typography';
const databaseURL = "https://word-cloud-1e33e-default-rtdb.firebaseio.com/";
class Words extends React.Component {
constructor() {
super();
this.state = {
words: {}
};
}
_get() {
fetch(`${databaseURL}/words.json`).then(res => {
if(res.status != 200) {
throw new Error(res.statusText);
}
return res.json();
}).then(words => this.setState({words: words}));
}
shouldComponentUpdate(nextProps, nextState) {
return nextState.words != this.state.words
}
componentDidMount() {
this._get();
}
render() {
return (
<div>
{Object.keys(this.state.words).map(id => {
const word = this.state.words[id];
return (
<div key={id}>
<Card>
<CardContent>
<Typography color="textSecondary" gutterBottom>
가중치: {word.weight}
</Typography>
<Typography variant="h5" component="h2">
{word.word}
</Typography>
</CardContent>
</Card>
<br/>
</div>
);
})}
</div>
);
}
}
export default Words;
'React & Next.js' 카테고리의 다른 글
React와 Firebase로 앱 개발하기 - 파이어베이스(Firebase)로 React 앱 배포 (CopyWebpackPlugin 버전 에러 관련 문제 해결 완료....) (0) | 2021.03.15 |
---|---|
React와 Firebase로 앱 개발하기 - 단어(Word) 데이터 삽입 및 삭제 기능 구현하기 (0) | 2021.03.15 |
React와 Firebase로 앱 개발하기 - 페이지 라우팅 (0) | 2021.03.15 |
React & Firebase 로 앱 개발하기 - 내비게이션 바 만들기 (0) | 2021.03.15 |
React & Firebase 로 앱 개발하기 - react 앱 개발환경 구축하기 (0) | 2021.03.14 |