Skip to content

Commit b22f1cb

Browse files
committed
base usage addition
1 parent ce91561 commit b22f1cb

File tree

1 file changed

+81
-1
lines changed

1 file changed

+81
-1
lines changed

readme.md

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,83 @@
11
# preact-native
22

3-
Experimental stuff, wouldn't recommend using
3+
> **Warning**: This is an experimental approach at creating a renderer for
4+
> preact
5+
6+
> **Note**: untill this reaches v1.0.0, the entire featureset might change,
7+
> since we are still figuring out what works best
8+
9+
I wouldn't really recommend using this for production but putting down the base
10+
usage setup so that anyone who'd wish to help with development can at least get
11+
a test environment ready.
12+
13+
## Install
14+
15+
```sh
16+
$ npm install @barelyhuman/preact-native preact
17+
```
18+
19+
## Usage
20+
21+
1. Setup a base react native project using `npx react-native init`
22+
2. Change the index.js to look like so
23+
24+
```js
25+
import { Renderer } from "@barelyhuman/preact-native";
26+
import { AppRegistry } from "react-native";
27+
import App from "./App";
28+
import { name as appName } from "./app.json";
29+
30+
const Main = () => {
31+
return <Renderer rootNode={App} />;
32+
};
33+
34+
AppRegistry.registerComponent(appName, () => Main);
35+
```
36+
37+
3.Now, the `App.js` file and sub components can be written using preact, heres
38+
an example.
39+
40+
```js
41+
// App.js
42+
/** @jsxImportSource preact */
43+
import { makeComponent } from "@barelyhuman/preact-native/src";
44+
import { signal } from "@preact/signals"; // => install this if you are using this example
45+
46+
import {
47+
SafeAreaView as RSafeAreaView,
48+
Text as RText,
49+
TouchableOpacity as RTouchableOpacity,
50+
} from "react-native";
51+
52+
const SafeAreaView = makeComponent(RSafeAreaView, "SafeAreaView");
53+
const Text = makeComponent(RText, "Text");
54+
const TouchableOpacity = makeComponent(RTouchableOpacity, "TouchableOpacity");
55+
56+
const count = signal(0);
57+
58+
const r = Math.random();
59+
export default function Home() {
60+
return (
61+
<SafeAreaView>
62+
<TouchableOpacity
63+
onPress={() => {
64+
count.value += 1;
65+
}}
66+
>
67+
<Text style={{ color: "dodgerblue", padding: 8 }}>{count.value}</Text>
68+
</TouchableOpacity>
69+
</SafeAreaView>
70+
);
71+
}
72+
```
73+
74+
## Why ?
75+
76+
It seemed like a nice project to try out my limits in terms of complicated stuff
77+
and also because I got bored of building websites. Also, I personally think
78+
preact has become a lot more stable and has less breaking changes every 3
79+
versions thus making it easier to maintain and upgrade older projects.
80+
81+
## License
82+
83+
[MIT](/LICENSE) &copy; [reaper](https://reaper.is)

0 commit comments

Comments
 (0)