Fetch Data with useEffect - React Typing CST Test
Loading…
Fetch Data with useEffect — React Code
Fetches data from API and displays it using useEffect and useState.
import React, { useEffect, useState } from 'react';
const DataFetcher = () => {
const [data, setData] = useState([]);
useEffect(() => {
fetch('https://jsonplaceholder.typicode.com/posts')
.then(res => res.json())
.then(setData);
}, []);
return <ul>{data.map(item => <li key={item.id}>{item.title}</li>)}</ul>;
};
export default DataFetcher;React Language Guide
React is a declarative, component-based JavaScript library for building user interfaces, primarily for single-page applications. It allows developers to create reusable UI components and manage application state efficiently.
Primary Use Cases
- ▸Single-page web applications (SPAs)
- ▸Dynamic user interfaces for web apps
- ▸Mobile apps via React Native
- ▸Reusable component libraries
- ▸Interactive dashboards and admin panels
Notable Features
- ▸Component-based architecture
- ▸Virtual DOM for optimized rendering
- ▸JSX syntax for combining HTML and JS
- ▸One-way data binding (props)
- ▸Hooks for state and lifecycle management
Origin & Creator
Developed by Jordan Walke at Facebook in 2013.
Industrial Note
React is specialized for building dynamic, responsive web and mobile UIs, particularly in SPA and complex front-end applications.