@raina Для начала Вам нужно импортировать библиотеку axios в Ваш проект и затем Вы можете начать использовать ее в React.js, посмотрите ниже пример использования библиотеки axios с React.js чтобы получить последние темы:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import React, { useState, useEffect } from "react"; import ReactDOM from "react-dom"; import axios from "axios"; const Main = () => { const [threads, setThreads] = useState(); // Получить последние записи const getLatestThreads = async () => { const res = await axios("https://dropcode.ru/api/thread/latest").then( (res) => res.data ); setThreads(res.threads); }; useEffect(() => { getLatestThreads(); }, []); return ( <div> {threads && threads.map((thread) => ( <div className="item"> <a target="_blank" rel="noreferrer" href={`https://dropcode.ru.ru/thread/${thread.slug}`} key={thread.id} > {thread.name} </a> </div> ))} </div> ); }; class App extends React.Component { render() { return <Main />; } } ReactDOM.render(<App />, document.getElementById("container")); |