DEV Community

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

Posted on • Edited on

7 3

🐶 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 = 'https://api.github.com/repos/axios/axios';

  return <div>
    <h1>Axios</h1>
    <p>{
      axios.get(url).then(response => response.data.description)
    }</p>
  </div>
}
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 https://github.com/recksjs/recks-starter-project.git
cd recks-starter-project
npm i
npm start

Or use this online sandbox

The source code is available at github.com/recksjs/recks

The end

header photo by Elena Koycheva on Unsplash

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay