Похожие чаты

Const loadCommit = () => fetch("http://localhost:8080/api")

.then(res => {
if (res.ok) return res;
else throw new Error("Yikes");
})
.then(res => res.json())
.catch(err => {
throw new Error(err.message)
});

function App() {
return (
<Async promiseFn={loadCommit}>
{({data, err, loading}) => {
if (loading) return "Loading..."
if (err) return (
<div>
<p>{err.message}</p>
</div>
)
if (data)
return (
<div>
<p>{data.message}</p>
<p>{data.id}</p>
</div>
)
}}
</Async>
);
}

How do I make it return actual html on error?

I'm changing port in the URL and it just prints GET http://localhost:8081/api net::ERR_CONNECTION_REFUSED in console 😐

15 ответов

13 просмотров

instead of throwing back err.message, try the status code or something, and have conditions for different status codes

Is this ReactJS?

Пользователь 61024
Yes

Why don't you use state?

Пользователь-61024 Автор вопроса
Darvesh 🍀
Why don't you use state?

I use it in our work projects, but I'm using them by looking at already written code by someone else So I'm kinda familiar with how stuff in react works, but I'm not sure what to use and when

Пользователь 61024
I use it in our work projects, but I'm using them ...

I'm not a frontend dev but check this kek https://codesandbox.io/s/hardcore-wood-45pry

Пользователь-61024 Автор вопроса
Darvesh 🍀
I'm not a frontend dev but check this kek https://...

Argument type function(): Promise<void> is not assignable to parameter type EffectCallback ... Type function(): Promise<void> is not assignable to type () => (void | (() => (void | undefined))) Type Promise<void> is not assignable to type void | (() => (void | undefined)) 😐😐😐

shouldn't you return the promise in your loadCommit function? otherwise how the Async component your passing the function to should know about the response

Пользователь-61024 Автор вопроса
Пользователь 61024
yeah, this is what I'm reading about now

If your looking for how to make it better, always abstract your data fetching logic into a custom hook with a proper name. Also look into libraries like 'react-query' that help you with this

Пользователь 61024
Argument type function(): Promise<void> is not ass...

I updated, check this now https://codesandbox.io/s/hardcore-wood-45pry?file=/src/App.js

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта