Where should I make AJAX and API calls in React.js function components?

前端 未结 2 1685
挽巷
挽巷 2021-01-27 11:36

I\'ve been learning more about React.js function components and have started transitioning one of my React.js applications to use them instead of the standard react components.

2条回答
  •  清歌不尽
    2021-01-27 12:15

    You can use react-pure-lifecycle to add lifecycle functions to functional components.

    Example:

    import React, { Component } from 'react';
    import lifecycle from 'react-pure-lifecycle';
    
    const methods = {
        componentDidMount(props) {
        //ajax call here
        }
    };
    
    const Channels = props => (
          

    Hello

    ) export default lifecycle(methods)(Channels);

提交回复
热议问题