DEV Community

Cover image for 🐶 Promises in Recks: Rx+JSX experiment
Kostia Palchyk
Kostia Palchyk

Posted on • Updated on

🐶 Promises in Recks: Rx+JSX experiment

In the previous episode we saw that streams are native to Recks:

function App() {
  const clock$ = timer(0, 1000);

  return <div>{ clock$ }</div>
online sandbox

Well, the same applies to Promises!

function App() {
  const delayed = Promise.resolve('Hello!');

  return <div>{ delayed }</div>

Once the engine receives a promise — it waits for it to resolve and then renders the result in place!

Let's see an example using axios, requesting its github repo description via github API (yep, we'll use axios to know what axios is 🧐):

import axios from 'axios';

function App() {
  const url = '';

  return <div>
      axios.get(url).then(response =>
online sandbox

That's it. No need to keep a state in the component or update a store. You just use async values where you need them!

As simple as that 🙂

To try Recks 🐶

Clone the template repository:

git clone --depth=1
cd recks-starter-project
npm i
npm start

Or use this online sandbox

The source code is available at

The end

header photo by Elena Koycheva on Unsplash

Top comments (0)