Forgo is a 4KB library that makes it super easy to create modern web apps using JSX (like React).
A Forgo Component is a function that returns an object with a render() function. The render function is called for the first render, and then subsequently for each rerender.
Mounting the Component#
Use the mount() function once your document has loaded.
Child Components and Passing Props#
That works just as you'd have seen in React.
Reading Form Input Elements#
You can read form input element values with regular DOM APIs.
There's a small hurdle though - how do we get a reference to the actual DOM element? That's where the ref attribute comes in. An object referenced by the ref attribute in an element's markup will have its value property set to the actual DOM element.
Better explained with an example:
When a component is unmounted, Forgo will invoke the unmount() function if defined for a component. This is of course, totally optional.
Recap with a complete example#
Finally, let's do a recap with a more complete example. Let's make a Todo List app in TypeScript.
There will be three components:
- TodoList (the main component)
Here's the TodoList, which hosts the other two components.
Here's the TodoListItem component, which simply displays a Todo.
And here's the AddTodo component. It takes an onAdd function from the parent, which gets called whenever a new todo is added.
That's all. Mount it, and we're ready to go.
Forgo uses the latest JSX createElement factory changes, so you might need to enable this with Babel. More details here: https://babeljs.io/docs/en/babel-plugin-transform-react-jsx
For your babel config:
If you're using TypeScript, add the following lines to your tsconfig.json file.
You can reach out to me via twitter or email. If you find issues, please file a bug on Github.