@vimpak/jsx 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +33 -26
  2. package/package.json +5 -1
package/README.md CHANGED
@@ -36,42 +36,26 @@ const html = await render(<Greeting name="World" />);
36
36
  // Output: <h1>Hello, World!</h1>
37
37
  ```
38
38
 
39
- ### Fragments
39
+ ### Async Components
40
40
 
41
- ```tsx
42
- function Page() {
43
- return (
44
- <>
45
- <h1>Title</h1>
46
- <p>Content</p>
47
- </>
48
- );
49
- }
50
- ```
51
-
52
- ### Safe HTML
53
-
54
- Use the `safe` prop to render raw HTML:
41
+ Components can be asynchronous:
55
42
 
56
43
  ```tsx
57
- function Component() {
58
- return <div safe="<strong>Bold text</strong>" />;
44
+ async function User({ id }: { id: string }) {
45
+ const user = await fetchUser(id);
46
+ return <div>{user.name}</div>;
59
47
  }
60
- ```
61
48
 
62
- ### Styles
63
-
64
- ```tsx
65
- function Styled() {
66
- return <div style={{ color: "red", fontSize: "16px" }}>Styled</div>;
67
- }
49
+ const html = await render(<User id="1" />);
68
50
  ```
69
51
 
52
+ The `render` function awaits all async components automatically.
53
+
70
54
  ### Context
71
55
 
72
56
  ```tsx
73
57
  class AppContext {
74
- async getTheme() {
58
+ getTheme() {
75
59
  return "dark";
76
60
  }
77
61
  }
@@ -79,7 +63,8 @@ class AppContext {
79
63
  const ctx = new AppContext();
80
64
 
81
65
  function Greeting(props: { name: string }, ctx: AppContext) {
82
- return <div></div>;
66
+ const theme = ctx.getTheme();
67
+ return <div className={theme}>{props.name}</div>;
83
68
  }
84
69
 
85
70
  function App() {
@@ -93,6 +78,24 @@ function App() {
93
78
  const html = await render(<App />, ctx);
94
79
  ```
95
80
 
81
+ ### Safe HTML
82
+
83
+ Use the `safe` prop to render raw HTML:
84
+
85
+ ```tsx
86
+ function Component() {
87
+ return <div safe="<strong>Bold text</strong>" />;
88
+ }
89
+ ```
90
+
91
+ ### Styles
92
+
93
+ ```tsx
94
+ function Styled() {
95
+ return <div style={{ color: "red", fontSize: "16px" }}>Styled</div>;
96
+ }
97
+ ```
98
+
96
99
  ## API
97
100
 
98
101
  ### `render(element, context?)`
@@ -103,3 +106,7 @@ Renders a JSX element to an HTML string.
103
106
  - **context** (optional): A `Context` value for passing values to all components
104
107
 
105
108
  Returns `Promise<string>`.
109
+
110
+ ## Thanks
111
+
112
+ - https://github.com/kitajs/html
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "type": "module",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "name": "@vimpak/jsx",
5
5
  "collaborators": [
6
6
  "Sudesh Yadav <sudeshyadav955@gmail.com>"
@@ -8,6 +8,10 @@
8
8
  "files": [
9
9
  "./dist"
10
10
  ],
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/sudesh955/jsx"
14
+ },
11
15
  "main": "./dist/index.js",
12
16
  "exports": {
13
17
  ".": {