jtsx-loader 0.1.11 → 0.1.12

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 +35 -23
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -106,29 +106,41 @@ app.listen(port, () => {
106
106
 
107
107
  ```jsx
108
108
  const Component = async ({ message }) => {
109
- const exampleObject = { example: 'object' };
110
-
111
- return (
112
- <>
113
- <html>
114
- <head>
115
- <title>{message}</title>
116
- </head>
117
- <body>
118
- <h2>{message}</h2>
119
-
120
- <pre>{JSON.stringify(exampleObject, null, 2)}</pre>
121
-
122
- <script>{`
123
- window.serverObject = ${JSON.stringify(exampleObject)};
124
- console.log(window.serverObject);
125
- `}</script>
126
- </body>
127
- </html>
128
- </>
129
- );
130
- };
131
-
109
+ // It's not a good practice to make queries here. This example demonstrates full asynchronuos JavaScript support within the template.
110
+ const exampleObject = { example: 'object'};
111
+
112
+ // Uncomment to test fetch
113
+ // const fetchOnEachRender = await fetch('https://httpbingo.org/json').then(r => r.json());
114
+
115
+ // Example with Fragment
116
+ return <>
117
+ {'<!DOCTYPE HTML>'}
118
+ <html>
119
+ <head>
120
+ <title>{message}</title>
121
+ </head>
122
+ <body>
123
+ <div>
124
+ <h2>{message}</h2>
125
+ <p>Example object</p>
126
+ <pre>{JSON.stringify(exampleObject, null, 4)}</pre>
127
+ <p>Open console to see same object passed from server inside JavaScript</p>
128
+
129
+
130
+ {/* Uncomment to test fetch */}
131
+ {/* <p>Response from <a href="https://httpbingo.org/json">https://httpbingo.org/json</a></p>
132
+ <pre>{JSON.stringify(fetchOnEachRender, null, 4)}</pre> */}
133
+ </div>
134
+ <script>{`
135
+ window.sum = 5 + 5;
136
+ console.log('window.sum', window.sum);
137
+ window.serverObject = ${JSON.stringify(exampleObject)}; // pass object from backend to frontend
138
+ console.log('window.serverObject', window.serverObject);
139
+ `}</script>
140
+ </body>
141
+ </html>
142
+ </>;
143
+ }
132
144
  export default Component;
133
145
  ```
134
146
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jtsx-loader",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "main": "./loader/register.mjs",
5
5
  "type": "module",
6
6
  "imports": {