vercel-labs / vercel-labs/json-render

Support dynamic data loading on UIElement mount

Open
#245 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
16.8k
Forks
901
Avg merge
3h 14m
Merged PRs (30d)
4

Description

Hi everyone,

I’m trying to define, from JSON, that a component should call an external API when it mounts in order to populate its state, but I haven’t found a way to do it.

Could you please confirm whether this is currently supported, and if so, what the recommended approach would be?

For example:

{
  "root": "username",
  "elements": {
    "username": {
      "type": "Text",
      "props": { "content": { "$state": "/user/name" } },
      "children": []
    }
  },
  "state": {
    "user": undefined
  },
  "on": {
    "mount": [
      { "action": "fetchUser" }
    ]
  }
}

The idea is that fetchUser would internally perform a fetch request, retrieve the user data, and then update the component state accordingly.

Is this currently possible?
If not, is there an alternative or recommended pattern to achieve this behavior?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how UIElement mount events, JSON-defined actions, and component state updates are currently handled. Check whether an action such as fetchUser can perform asynchronous work and write returned data into state. Done should be a documented, working pattern—or a clearly stated limitation and recommended alternative for loading external data.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.