Professional Documents
Culture Documents
Efm Regional React 1
Efm Regional React 1
PARTIE 1:
QUESTION 1:
<BrowserRouter>
<Layout />
</BrowserRouter>
QUESTION 2:
function Layout() {
return (
<div>
<ul>
<li>
<Link to='/'>Home</Link>
</li>
<li>
<Link to='/contact'>Contact</Link>
</li>
<li>
<Link to='/form'>Form</Link>
</li>
<li>
<Link to='/article'>Article</Link>
</li>
</ul>
<Routes>
<Route path='/' element={<Home />} />
<Route path='/contact' element={<Contact />} />
<Route path='/form' element={<Form />} />
<Route path='/article' element={<Article />} />
<Route path='*' element={<NoPage />} />
</Routes>
</div>
);
}
QUESTION 3:
import React, { useEffect, useState } from 'react';
import axios from 'axios';
useEffect(() => {
axios.get('https://fakestoreapi.com/products').then((res) =>
setProducts(res.data));
}, []);
return (
<div>
<ul>
{
products.map((p) => {
return (
<li key={p.id}>
<img src={p.image} alt="" style={{
maxWidth: '400px',
}} />
<p>{p.title}</p>
<p><b>PRIX: {p.price} MAD</b></p>
</li>)
})
}
</ul>
</div>
)
}
QUESTION 4:
useEffect(() => {
fetch('https://countriesnow.space/api/v0.1/countries').then(res =>
res.json()).then(res => setPaysData(res.data));
}, [])
return (
<div>
<form onSubmit={handleSubmit}>
<div>
<label>Email</label>
<input type="email" value={email} onChange={(e) => setEmail(e.target.value)}
/>
</div>
<div>
<label>motDePasse</label>
<input type="password" value={motDePasse} onChange={(e) =>
setMotDePasse(e.target.value)} />
</div>
<div>
<label>Pays</label>
<select value={pays} onChange={(e) => setPays(e.target.value)}>
<option value="">-- select pays --</option>
{
paysData.map((p, index) => (
<option key={index} value={p.iso2}>{p.country}</option>
))
}
</select>
</div>
<div>
<label>Genre </label>
<br />
<label>
<input type="radio" name="genre" value='male' onChange={(e) =>
setGenre(e.target.value)} checked={genre === 'male'} />
Male
</label>
<label>
<input type="radio" name="genre" value='female' onChange={(e) =>
setGenre(e.target.value)} checked={genre === 'female'} />
Female
</label>
</div>
<button>Valider</button>
</form>
</div>
)
}
QUESTION 1:
QUESTION 2:
index.js
QUESTION 3:
QUESTION 4 et 5:
// Q4:
export const ADDARTICLE = 'ADDARTICLE';
// Q5:
export const REMOVEARTICLE = 'REMOVEARTICLE';
QUESTION 6 et 7:
const initialState = {
panier: []
};
QUESTION 8: