Component System
Create interactive UI components with state management and lifecycle events
Modern Server-Side React Framework
A powerful framework that brings React-like features to Express applications
React Express is a powerful framework that brings React-like features to Express applications. It provides a modern, component-based approach to building server-rendered applications with client-side interactivity.
npm install advanced-express
import path from "path";
import express from "express";
import { Server } from "http";
import { Server as SocketIOServer } from "socket.io";
import { reactExpress } from "advanced-express";
const app = express();
const port = 3000;
const server = new Server(app);
const io = new SocketIOServer(server);
app.set("server", server);
app.use(express.static(path.join(__dirname, "public")));
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "ejs");
const middleware = reactExpress({
viewsDir: path.join(__dirname, 'views'),
hmr: true
});
// Apply the middleware
middleware(app);
app.get("/", (req, res) => {
res.render("index");
});
server.listen(port, () => {
console.log(`Server running on http://localhost:${port}`);
});
<!-- views/index.ejs -->
<div id="counter">
<span class="count">0</span>
<button id="increment">+</button>
<button id="decrement">-</button>
</div>
<script>
const counter = ReactExpress.components.createComponent(
document.getElementById('counter'),
{
initialState: { count: 0 },
init: (component) => {
component.listen('#increment', 'click', (e, comp) => {
comp.setState(state => ({ count: state.count + 1 }));
});
component.listen('#decrement', 'click', (e, comp) => {
comp.setState(state => ({ count: state.count - 1 }));
});
},
render: (state, element) => {
element.querySelector('.count').textContent = state.count;
}
}
);
</script>
Components are the building blocks of your application. Each component has:
React Express seamlessly integrates with Express:
Learn more about server integration
Multiple ways to manage state:
Learn more about state management
Built-in form handling features:
Development features:
const sharedState = ReactExpress.components.createSharedState({
user: null,
theme: 'light'
});
const userProfile = ReactExpress.components.createComponent(
document.getElementById('profile'),
{
init: (component) => {
sharedState.subscribe(state => {
component.setState({ user: state.user });
});
}
}
);
interface UserState {
name: string;
email: string;
}
const profile = ReactExpress.components.createComponent<UserState>(
document.getElementById('profile')!,
{
initialState: {
name: '',
email: ''
}
}
);
const notifications = ReactExpress.components.createComponent(
document.getElementById('notifications'),
{
init: (component) => {
const eventSource = new EventSource('/api/notifications');
eventSource.onmessage = (event) => {
component.setState(state => ({
messages: [...state.messages, JSON.parse(event.data)]
}));
};
}
}
);
Component Organization
State Management
Performance
Error Handling
We welcome contributions! Please see our contributing guide for details.
MIT License - see LICENSE for details.