C-React is a framework that enables building React-based web applications using pure C code. It compiles to WebAssembly via Emscripten and provides intuitive bindings to React's JavaScript API:
- Write C code with React-like components
- Compile to WebAssembly with Emscripten
- Run React applications in the browser
This framework is designed for developers who need to:
- Build web UIs with C code compiled to WebAssembly
- Leverage React's component model from native C
- Create high-performance browser applications
- Integrate existing C codebases with modern web frontends
- React Integration - Full C bindings for React 18 API
- WebAssembly Compilation - Compile C directly to browser-compatible WASM
- Event Handling - Simple callbacks for clicks, inputs, and custom events
- Component System - Create reusable UI components in pure C
- Zero JavaScript Required - Write entire applications in C
- Browser APIs Access - Direct access to DOM and window objects via c2wasm
Want to build your first C-React application? Follow the Installation Guide for step-by-step instructions, including creating an HTML template and compiling your first component.
| File | What is |
|---|---|
| react.c | C-React framework bindings |
Dependencies:
- c2wasm.c - C to WebAssembly bridge library (required)
| Document | Description |
|---|---|
| Installation Guide | Complete setup instructions for all platforms |
| Document | Description |
|---|---|
| Element Handling | Creating and manipulating HTML elements |
| Callback Handling | Event handlers, clicks, inputs, and custom callbacks |
| Document | Description |
|---|---|
| CLAUDE.md | Project architecture and development guide for AI assistants |
#include <stdio.h>
#include "c2wasm.c"
#include "react.c"
ReactRoot root;
void rootRender();
static int counter = 0;
void handleClick() {
counter++;
rootRender();
}
void rootRender() {
char buffer[50];
sprintf(buffer, "Count: %d", counter);
ReactComponent app = ReactCreateElement(
"div",
ReactCreateProps(
"style", ReactCreateProps(
"padding", ReactCreateString("20px")
)
),
ReactCreateElement("h1", ReactNULL,
ReactCreateString("C-React Counter")
),
ReactCreateElement("button",
ReactCreateProps(
"onClick", ReactCreateClickHandler(handleClick)
),
ReactCreateString("Increment")
),
ReactCreateElement("p", ReactNULL,
ReactCreateString(buffer)
)
);
ReactRootRender(root, app);
}
int main() {
ReactStart();
root = ReactDOMCreateRoot(ReactGetElementById("root"));
rootRender();
return 0;
}Compile with:
emcc app.c -o app.jsThis project is licensed under the Public Domain - see the LICENSE file for details.
The c2wasm dependency is licensed under the MIT License.