reactのメモ
reactメモ
props
propsはコンポーネントを初期化する時に設定できる値。 後からは変更できない
this.state.logged_in
ログインしているかを判定する
jwt認証の時にはfetchにaccess tokenを加える
fetch('http://127.0.0.1:8000/api/insert_memo/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `JWT ${localStorage.getItem('token')}`
},
body: JSON.stringify({
name: 'Hubot',
login: 'hubot',
})
}).then(function(response) {
// レスポンス結果
console.log(response);
window.alert('Response: ' + response);
}, function(error) {
// エラー内容
window.alert('Error: ' + error);
});
render()
以下には1つのブロックしか入らない
render(){
return
}
Componentと
https://ja.reactjs.org/docs/react-component.html
state
Componentの状態を表す
fetch
fetchはGET、POST処理などを担う
=> アロー関数
これはReact特有というものではない
let func = (x) => {
console.log(x);
}
xが引数