你可以使用React Query来进行慢速计算,而不仅仅是API

React Query brings the ergonomics of GraphQL clients to RESTful APIs. It scratched my itch.

React Query为RESTful API带来了GraphQL客户端的人性化设计。它搔到了我的痒处。

Getting a whole company onto a new way of writing the API layer is hard and there's real work to do. React Query offers the perfect middle ground.

让整个公司采用新的方式来编写API层是很难的,而且有真正的工作要做。React Query提供了一个完美的中间地带。

Keep the RESTful API you're used to, get the request deduping, data caching, loading states, re-fetching, and hooks ergonomics you dream of. ?

保持你习惯的RESTful API,获得你梦想的重复请求、数据缓存、加载状态、重新获取和钩子的人体工程学。?

You can use those same ergonomics for any slow operation. Doesn't have to be an API call.

你可以在任何缓慢的操作中使用这些相同的人体工程学原理。不一定非得是API调用。

Say you're parsing a CSV client-side.

假设你在客户端解析一个CSV。

You could run a file upload, parse and validate on the server, respond with any errors, and tell the user what happened. That's the usual approach and it's okay.

可以运行一个文件上传,在服务器上进行解析和验证,回应任何错误,并告诉用户发生了什么。这就是通常的做法,也是可以的。

A better approach is to use a library like Papa Parse. Load file into browser memory or use a link, parse and validate, show the user what happened, ask for confirmation, send parsed JSON to your API.

一个更好的方法是使用一个像Papa Parse这样的库。将文件加载到浏览器内存或使用一个链接,解析和验证,向用户显示发生了什么,要求确认,将解析后的JSON发送到你的API。

Here's an example that parses and displays Taylor Swift Spofity data from Kaggle.

这里有一个例子,解析并显示来自Kaggle的Taylor Swift Spofity数据

We're using a trick to load the CSV – Webpack imports it as a data URL and fetch() parses that data into a File format. This is okay for a demo, but bloats your bundle size. You should use client-side file reading for a serious project.

我们使用了一个技巧来加载CSV--Webpack将其作为一个数据URL导入,然后fetch() ,将数据解析成一个文件格式。这对于一个演示来说是可以的,但会使你的包的大小膨胀。在一个严肃的项目中,你应该使用客户端的文件读取

Do thing, set state, yawn

做事情,定状态,打哈欠

You have to write your bazillionth state setter. Boilerplate you could write in your sleep, if it wasn't so easy to write a bug.

你必须写出你的第1亿个状态设置器。你可以在睡梦中写出模板,如果不是那么容易写出一个错误的话。

const [taylorSwiftSongs, setTaylorSwiftSongs] = useState([])

const [taylorSwiftSongs, setTaylorSwiftSongs] = useState([] )

...
开通本站会员,查看完整译文。

首页 - Wiki
Copyright © 2011-2025 iteam. Current version is 2.144.0. UTC+08:00, 2025-07-08 05:20
浙ICP备14020137号-1 $访客地图$