cra-hyperapp
v0.1.0
Published
Hyperapp expansion pack for create-react-app
Downloads
14
Readme
Hyperapp for zero-configuration create-react-app style projects
Starting a new project
Start by creating a new folder for your awesome new Hyperapp project and initialize a new project with npm.
mkdir my-awesome-project
cd my-awesome-project
mkdir public src
npm init -y
Install your dependencies (they're good for your health).
npm i hyperapp
npm i -D cra-hyperapp
Then open your package.json
in your favorite text editor and add your scripts.
"scripts": {
+ "start": "hyperapp-scripts",
+ "build": "hyperapp-scripts build"
},
Create a public/index.html
file.
<!doctype html>
<html>
<head>
<title>My awesome app!</title>
</head>
<body></body>
</html>
Next create a src/index.js
file with a basic hello world app.
import { h, app } from "hyperapp"
const state = { title: "Hi." }
const actions = {}
const view = state => <h1>{state.title}</h1>
app(state, actions, view, document.body)
Finally start your app and gaze upon its glory.
npm start
Congratulations! Your app is now ready to make even more awesome! 😎
A 12 step recovery program for kicking your React/Redux habit in favor of Hyperapp
- Remove the
react
,react-dom
,redux
, andreact-redux
dependencies.
npm rm react react-dom redux react-redux
- Add the
hyperapp
andcra-hyperapp
dependencies.
npm i hyperapp cra-hyperapp
- Replace
react-scripts
withhyperapp-scripts
in yourpackage.json
.
"scripts": {
- "start": "react-scripts start",
- "build": "react-scripts build"
+ "start": "hyperapp-scripts start",
+ "build": "hyperapp-scripts build"
},
- Remove your Redux
store
.
rm src/store.js
- Replace
import React from "react"
withimport { h } from "cra-hyperapp"
. This gives some compatibility features likeonClick
style support and children as a component prop instead of 2nd argument.
-import React from "react"
+import { h } from "cra-hyperapp"
- Replace the
ReactDOM.render
withapp
fromhyperapp
using thewithReducer
HOA to pass your root reducer.
-import React from "react";
-import { render } from "react-dom";
-import { Provider } from "react-redux";
-import store from "./store";
+import { h, withReducer } from "cra-hyperapp";
+import { app } from "hyperapp";
+import reducer from "./reducer";
-render(
+withReducer(reducer)(app)(
+ state,
+ actions,
- <Provider store={store}>
- <App />
- </Provider>,
+ (state, actions) => <App />,
document.getElementById("root")
);
- Replace
import { connect } from "react-redux"
withimport { connect } from "cra-hyperapp"
.
-import { connect } from "react-redux";
+import { connect } from "cra-hyperapp";
Your app should now be back in a working state. Verify this before going full Hyperapp.
- Move your action/reducer combinations over to native Hyperapp one at a time.
- Move your components over to native Hyperapp one at a time to use the built-in
h
and removing theconnect
HOC (this happens somewhat simultaneously with the last step).
-import { h, connect } from "cra-hyperapp"
+import { h } from "hyperapp";
- Remove the
withReducer
HOA from yourapp
.
-import { withReducer } from "cra-hyperapp";
import { h, app } from "hyperapp";
-import reducer from "./reducer";
-withReducer(reducer)(app)(
+app(
state,
actions,
view,
document.getElementById("root")
);
- Delete your reducer.
rm src/reducer.js
- Profit with Hyperapp. 💰