Example code for asynchronous server requests: Meteor Methods and React useState() and useEffect

I needed to request some markdown text stored in a file from the server and render in a React component. This situation is not well suited to the normal “store in a collection, then publish to the client” approach. After a little bit of head-scratching, I figured out how to combine Meteor Method and React useState() and useEffect() to do this. It’s only 20 lines of code, and I think it’s a pretty generally useful design pattern:

The Meteor Method is here. Note that it’s helpful to disable the Optimistic UI stuff:

Enjoy!