Back to tasksGet help with live coding in real time with Sobes Copilot
Junior — Senior
33
Компонент получения данных пользователя
Companies where asked:
HR SIGNAL
Task condition
Создайте React‑компонент, который принимает идентификатор пользователя и отображает его сведения. Для получения данных используйте функцию fetchUser. Если идентификатор отсутствует или пользователь не найден – компонент ничего не выводит.
type Props = {
userId: number | null;
}
export const User: FC<Props> = ({ userId }) => {
// Write your solution here
const user = userId && fetchUser({ id: userId });
if (!user) return null;
return (
<div className="stack column">
<div>UserId: </div>
<div>UserName: </div>
</div>
);
};
const Loader = () => <p data-testid="loader">Loading...</p>
const Error = ({ e } : {e: AxiosError}) => {
<p style={{ color: "red" }} data-testid="error">
{e.message}
</p>
}