What’s the Right Way to get and save remote data for a Gutenberg block?

Đã có trọn bộ đề thi thử THPT Quốc Gia 2022 các môn: vip.dethihsg247.com
QUẢNG CÁO: Đổi thẻ cào thành tiền mặt min rút 10k tại đây

I’m writing a new block, where one of the pieces of input is a URL to a remote API. That remote API returns some data (in the first instance, a CSV file), which should be saved locally, and then is accessed by the front-end of the block (i.e., I have to get the name/URL of the local file to some front-end javascript).

The way I’m doing it right now is, I’ve implemented my own route and endpoint for the REST API, so that when the author inputs the URL in the editor, it does a PUT to my endpoint. The backend grabs the remote file from that URL, stores it locally, and returns the local file name. That response to the REST API (the local file name) is then stored in another attribute in the block.

Someone pointed out that this probably isn’t correct, as I probably shouldn’t be retrieving that remote data or saving anything until the post is saved. What’s the Right Way to do this?

Xin chào các bạn và quý Thầy Cô. Hãy nhập từ khóa mình muốn vào ô tìm kiếm trên Website để tìm kiếm mọi thứ hoặc trên google các bạn hãy nhập từ khóa + dethihsg247.com để tìm kiếm các bài viết của chúng tôi nhé.
  • Hiện tại chúng tôi có hơn 25 nghìn bài văn mẫu các thể loại.
  • Kho tài liệu, đề thi học sinh giỏi các lớp vô cùng phong phú.
  • Mỗi ngày cập nhật hơn 100 đề thi chất lượng từ các website bán tài liệu lớn.

Tải đề thi VIP với giá siêu rẻ tại Vip.Dethihsg247.Com