Getting started
Basic Usage
React JSONR allows you to render React components from JSON definitions. This guide will walk you through the basics of using the library.
Core Concepts
Before diving into the code, let's understand the core concepts of React JSONR:
- JSON Node: A JSON structure describing a component, its props, and children
- Component Registry: A mapping of component types to their implementations
- Event Handler Mapping: A way to safely map string references to actual functions
- Transformation Pipeline: A system to process and modify the JSON before rendering
- Plugins: Modular transformers that can alter the JSON tree
Simple Example
Let's start with a simple example of rendering a contact form from JSON:
Step-by-Step Breakdown
- Import the library: Import
renderNode
andtransformJsonTree
from react-jsonr - Define or import your components: These are the React components that will be referenced in your JSON
- Create a component registry: This maps type names in JSON to actual React components
- Define event handlers: Functions that can be referenced by string names in your JSON
- Create the JSON definition: Describe your UI structure using JSON nodes
- Transform the JSON (optional): Apply plugins to modify the JSON before rendering
- Render to React elements: Use
renderNode
to convert the JSON into React elements - Use the elements: Render the generated elements in your React application
What's Next
Now that you understand the basics, you can:
- Learn about using plugins to enhance your JSON
- Check out more advanced examples
- Explore the API reference