
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
fpreact provides an alternative api for creating preact components, heavily inspired by elm.
fpreact provides an alternative api for creating preact components, heavily inspired by elm. The api includes redux style state management and lends itself to functional programming, avoiding the use of this
It has first class TypeScript support (it's written in it!), but also works great with regular JavaScript.
npm i -S fpreact preact
Find more in the examples
folder.
import { h, render, component, Message } from 'fpreact';
enum Msg {
UpdateName,
}
interface Model {
name: string;
}
type Messages = Message<Msg.UpdateName, string>;
const Greet = component<Model, Messages>({
update(model = { name: 'world' }, msg) {
switch (msg.kind) {
case Msg.UpdateName:
return { ...model, name: msg.value };
}
return model;
},
view(model, dispatch) {
return (
<div>
<h1>Hello, {model.name}</h1>
<label>
<span>Name:</span>
<input value={model.name} onInput={dispatch(Msg.UpdateName)} />
</label>
</div>
);
},
});
render(<Greet />, document.body);
import { h, render, component } from 'fpreact';
const Msg = {
// You don't have to use a number here.
// You could just as easily use "UPDATE_NAME" or anything else if you desire,
// just make sure each item has a unique value
UpdateName: 0,
};
const Greet = component({
update(model = { name: 'world' }, msg) {
switch (msg.kind) {
case Msg.UpdateName:
return { ...model, name: msg.value };
}
return model;
},
view(model, dispatch) {
return (
<div>
<h1>Hello, {model.name}</h1>
<label>
<span>Name:</span>
<input value={model.name} onInput={dispatch(Msg.UpdateName)} />
</label>
</div>
);
},
});
render(<Greet />, document.body);
'use strict';
var fpreact = require('fpreact');
var Msg = {
UpdateName: 0,
};
var Greet = fpreact.component({
update: function(model, msg) {
if (model == null) {
return { name: 'world' };
}
switch (msg.kind) {
case Msg.UpdateName:
return Object.assign({}, model, { name: msg.value });
}
return model;
},
view: function(model, dispatch) {
return fpreact.h(
'div',
null,
fpreact.h('h1', null, 'Hello, ', model.name),
fpreact.h(
'label',
null,
fpreact.h('span', null, 'Name:'),
fpreact.h('input', { value: model.name, onInput: dispatch(Msg.UpdateName) }),
),
);
},
});
fpreact.render(fpreact.h(Greet, null), document.body);
FAQs
fpreact provides an alternative api for creating preact components, heavily inspired by elm.
The npm package fpreact receives a total of 0 weekly downloads. As such, fpreact popularity was classified as not popular.
We found that fpreact demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.