Devcards For React

Browser Driven Component Development

A. Sharif
JavaScript Inside
Published in
4 min readMay 16, 2016

--

Introduction

React Cards is a library that aims to bring a visual REPL-like experience for React Developers when creating components.

It is heavily inspired by Bruce Hauman’s excellent Devcards project, which enables ClojureScript developers to quickly write components and gain visual feedback.

The benefits are clear once we see Devcards in full effect. First and foremost creating a Component inside an existing application is hard and is limited by the surrounding constraints. Everyone creating UI components inside a full fledged application knows how complex this can be. One solution is to use something like jsfiddle or codepen, but this suboptimal, as you still might need specific css classes or other modules that you can’t access when taking this route.

React Card is driven by the code, not static requirements defined via configs for example. React Cards tries to bring a similar Devcard experience to React developers, opening up the possibility to quickly test the look and feel as well as the behavior of a component. Furthermore enabling developers to write markdown and even run tests against the component, displaying the test results as a React component itself.

React Cards in action

This approach has many benefits. A component with multiple possible states can be difficult to test and document. With React Cards we can display the component in many different states along with documentation and tests to ensure nothing breaks while we’re working on the component.

Bruce Hauman created a short screen cast to highlight the benefits and effectiveness of this approach in Devcards.

Getting Started

Clone the React Cards repository https://github.com/steos/reactcards and run

React Cards will be available at http://localhost:8080

To see React Cards in action, go to the example directory and start experimenting.

Writing Cards

Take a look at the examples folder. There are several cards you can edit on the fly.

React Cards

Creating a Stateful Component

React Cards with Stateful Compoenent

Creating a Stateful Component with Undo/Redo

We can even add undo/redo capabilities to a React Card.

React Cards with undo/redo

Writing Tests

You can write your tests using enzyme or chai for example. Take a look at the test folder inside examples to see reference enzyme/chai tests.

You can write tests in a separate folder or write them directly inside a card. The first approach enables us to reuse the test in a different setting. This means we can reuse the same tests for both, React Cards as well as cli test. More on this in a separate post.

React Cards Tests

Ingredients

React Cards itself only consists of a minimal set of components and a simplified store for handling namespaces and cards. The weight lifting is mainly done by the improved react-hot-loader 3 by Dan Abramov and enzyme and chai for testing.

Outro

This easiest way is to checkout https://github.com/steos/reactcards directly and experiment with the possibilities. Special thanks to Nik Graf for the inspiration.

React Cards is work in progress. If you have any questions or feedback please connect on twitter or connect with Stefan Oestreicher on twitter or leave a comment here.

--

--

A. Sharif
JavaScript Inside

Focusing on quality. Software Development. Product Management.