株式会社ヴァンデミックシステム

Blog

<スポンサーリンク>

呼ばれる側

  • コンポーネントが呼ばれて返す値にstateをセットすると別コンポーネントから呼び出すことができる

 

class GetPod extends Component {
    constructor(props) {
        super(props);
        this.state = {
            podstatus: ''
        }
    }

    // renderの前に実行される
    componentWillMount() {
    const request = axios.create({
            baseURL: "http://127.0.0.1:1323",
            method: "GET"
        })
        request.get("/getpodstatus")
            .then(request => {
                this.setState({
                    podstatus: request.data.items[0].status.phase
                })
                console.log(this.state.podstatus)
            })
    }

    // コンポーネントが呼ばれたらstateを返すようにする
    render() {
        return <p>{this.state.podstatus}</p> ;
    }
}

 

 

<スポンサーリンク>

コメントを残す

Allowed tags:  you may use these HTML tags and attributes: <a href="">, <strong>, <em>, <h1>, <h2>, <h3>
Please note:  all comments go through moderation.

*

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)