We all love React for its component-based architecture and declarative approach to building UIs. But let's be honest, managing state, especially as applications grow, can become a source of frustration. Boilerplate code, steep learning curves, and performance concerns often arise with popular solutions. What if there was a simpler way? A way that allows you to master React state management in just 5 minutes and significantly reduces bundle size?
๐จ The State Management Problem Weโve All Faced
If youโve been building React apps for a while, youโve probably hit one (or all) of these pain points:
- Redux: Powerful, but verbose and heavy. Bundle sizes balloon, and you spend too much time writing actions, reducers, and boilerplate.
- Zustand: Sleeker, but still larger than necessary and requires some manual care for memoization.
- Context + useReducer: Simple, but causes every consumer to re-render โ even when only a single value changes.
When I built React Foam, my goal was simple:
โ
Keep it as small as possible (under 1KB gzipped)
โ
Make the API so intuitive you can learn it in minutes
โ
Bake in performance optimizations you donโt have to think about
โ
Provide first-class TypeScript support without extra config
Why choose React Foam?
Unparalleled Simplicity: React Foam's intuitive API and hook-based design allow developers to grasp the basics and integrate it into their projects within minutes.
Featherlight Footprint: The 1KB size means minimal impact on your application's bundle size, crucial for performance optimization, particularly on mobile or bandwidth-constrained environments.
Reduced Boilerplate: Unlike libraries that demand extensive configuration and action/reducer definitions, React Foam lets you focus on your state logic, saving time and mental overhead.
Familiar React Experience: Leveraging hooks directly, React Foam feels like a natural extension of React, minimizing the learning curve for developers already comfortable with React hooks.
Scalable for Many Needs: While its primary focus is simplicity, React Foam's underlying design allows it to scale effectively for small-to-medium applications and specific use cases where size and ease of use are paramount.
๐ Quick Start (Yes, Itโs This Simple)
import { createStore } from 'react-foam';
// Create a store with initial state
const useCounterStore = createStore({ count: 0 });
function Counter() {
const count = useCounterStore(s => s.count);
return (
<button onClick={() =>
useCounterStore.setState(s => ({ count: s.count + 1 }))
}>
Count: {count}
</button>
);
}
No providers. No reducers. No mental overhead.
โ๏ธ How React Foam Stacks Up
Feature | React Foam | Zustand | Redux Toolkit | Context API |
---|---|---|---|---|
Bundle Size | ~1KB | ~8KB | ~45KB | 0KB |
Boilerplate | Minimal | Low | High | Medium |
Performance | Excellent | Good | Good | Poor |
TypeScript | Excellent | Good | Good | Manual |
Memoization | Built-in (memo ) |
Shallow compare | Manual | Manual |
DevTools | Planned | Yes | Excellent | Limited |
๐ Built for Performance
React Foam automatically prevents unnecessary re-renders:
- Selective Subscriptions โ Components only re-render when their selected state changes.
-
Memoized Selectors โ Built-in
memo
utility tracks dependencies automatically. - Efficient Store Internals โ Minimal listener overhead, with auto-cleanup on unmount.
๐ฏ Real-World Example: Preventing Re-Renders with memo
import { createStore, memo } from 'react-foam';
const useProductsStore = createStore({
products: [
{ id: 1, name: 'Laptop', inStock: true },
{ id: 2, name: 'Mouse', inStock: false }
],
lastUpdated: Date.now()
});
function InStockProducts() {
const inStock = useProductsStore(
memo(s => s.products.filter(p => p.inStock))
);
return (
<ul>{inStock.map(p => <li key={p.id}>{p.name}</li>)}</ul>
);
}
With memo
, updating lastUpdated
wonโt re-render this component โ even though the store changes.
๐ก Best Practices for Using React Foam
-
Keep Stores Small & Focused โ One store per domain (
useUserStore
,useCartStore
). - Use Selectors for Primitives โ Directly subscribe to primitive values for optimal performance.
-
Wrap Derived Data in
memo
โ Avoid re-renders from new arrays/objects. - Prefer Functional Updates โ Always work with the latest state.
๐ฃ Roadmap
- DevTools Integration (browser extension)
- Persistence Plugin (localStorage/sessionStorage)
- React Native Optimizations
- Framework-Agnostic Core (Vue, Svelte, etc.)
๐ Try It Today
๐ฆ Install:
npm install react-foam
# or
yarn add react-foam
React Foam is an open-source project and welcomes contributions from the community. We believe in collaboration and aim to foster a vibrant community around this library.
- Explore the Docs: Dive into the comprehensive documentation for detailed explanations, API references, and advanced usage patterns. Docs
Contribute on GitHub: Report issues, suggest features, or even submit pull requests to help improve React Foam.
GitHub Repo
NPM PackageShare Your Feedback: Join the conversation on [mention relevant social media or community platforms like Reddit] and share your experiences, challenges, and success stories with React Foam.*
Top comments (0)