Basic React components for building your own Solid components and apps
Switch branches/tags
Nothing to show
Clone or download
Latest commit b16d768 Nov 22, 2018

React for Solid

Basic React components for building your own Solid components and apps.

npm version Build Status Coverage Status Dependency Status

🚧 Work in progress: you currently get components to read data. Writing is still underway.


Solid is an ecosystem for people, data, and apps in which people can store their data where they want, independently of the apps they use.

⚛️ This library aims to:

  1. provide React developers with components to develop fun Solid apps 👨🏿‍💻
  2. enable React developers to build their own components for Solid 👷🏾‍♀️

Solid uses 🔗 Linked Data, so people's data from all over the Web can be connected together instead of needing to be stored in one giant space. This library makes working with Linked Data easier, too.

Example apps

These apps have already been built with React for Solid:

Installation and usage

First add the package:

yarn add @solid/react # or
npm install @solid/react

Then you can import components like this:

import { LoginButton, Value } from '@solid/react';


The demo app will inspire you on how to use the components listed below.

👮🏻‍♀️ Authentication

Showing different content to logged in users

  <p>You are not logged in, and this is a members-only area!</p>
  <p>You are logged in and can see the special content.</p>

Logging in and out

You will need a copy of popup.html in your application folder.

<LoginButton popup="popup.html"/>
// Shows LoginButton or LogoutButton depending on the user's status

🖥️ Showing Solid data

🈯 The LDflex language

Solid React data components use the LDFlex language to build paths to the data you want.

For example:

  • "user.firstName" will resolve to the logged in user's first name
  • "user.friends.firstName" will resolve to the first name of the user's friends
  • "[].homepage" will resolve to Ruben's homepage
  • "[].friends.firstName" will resolve to Ruben's friends' names

Learn how to write your own LDflex expressions.

Data components

  <p>Welcome back, <Value src="user.firstName"/></p>
  <Image src="user.image" defaultSrc="profile.svg" className="pic"/>
    <li><Link href="user.inbox">Your inbox</Link></li>
    <li><Link href="user.homepage">Your homepage</Link></li>

<h2>Random friend of <Name src="[]"/></h2>
<Value src="[].friends.firstName"/>

<h2>All friends</h2>
<List src="[].friends.firstName"/>

<h2>Random blog post</h2>
<Link href="[].blog[schema:blogPost]"/>

<h2>All blog posts</h2>
<List src="[].blog[schema:blogPost].label"/>

💪🏾 Building your own components

The Solid React library makes it easy to build your own components to interact with the current user and to fetch Linked Data from the Web. To this end, the library ships with Higher-Order Components that do the heavy lifting for your components.

The easiest way is to look at the implementation of built-in components like AuthButton, Name, and List. They are all relatively straightforward, since the complexity is abstracted by the mechanisms listed below.

import { withWebId, evaluateExpressions, evaluateList } from '@solid/react';

Components that access the user's WebID

In Solid, people are identified by a WebID, which is a URL that points to them and leads to their data.

By wrapping your component definition with withWebId, the webId property will automatically be set on your component's instances whenever the login status changes.

const MyComponent = withWebId(props =>
  <p>Hey user, your WebID is {props.webID}.</p>);

Components that use LDflex expressions

To use data from LDflex expressions, wrap your component definition with evaluateExpressions. The first argument is an array of properties in which you expect expressions. Your component will then get back the result in the property of the same name.

const MyComponent = evaluateExpressions(['name'], props =>
  <p>The name is {`${}`}.</p>);
<MyComponent name=""/>

Note how we force into a string through ${} (or, alternatively, or '' + This is needed because is a special object that looks like a string but isn't quite a string.

If a property contains a list of things rather than a single value, pass its name to the second parameter:

const MyComponent = evaluateExpressions(['name'], ['friends'], props =>
  <p>Your name is {`${}`} and you have {props.friends.length} friends.</p>);
<MyComponent name="" friends="user.friends"/>

Specifically for building lists of things, there is the evaluateList helper. The built-in List component is an example.

const Greetings = evaluateList('people', ({ people, greeting }) =>
  <ul>{ =>
    <li key={person}>{greeting} {`${person}`}!</li>
<Greetings people="user.friends" greeting="Hello"/>


©2018–present Ruben Verborgh, MIT License.