Skip to content

Commit 425d2d2

Browse files
committed
chore: adding examples folder
1 parent 9522725 commit 425d2d2

File tree

13 files changed

+951
-0
lines changed

13 files changed

+951
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# dependencies
44
/node_modules
5+
/examples/node_modules
56
/.pnp
67
.pnp.js
78

@@ -28,3 +29,4 @@ yarn-error.log*
2829
/**/*.bs.js
2930

3031
/lib
32+
/examples/lib

examples/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
node_modules
2+
.DS_Store
3+
dist
4+
dist-ssr
5+
*.local
6+
.merlin
7+
/lib
8+
.bsb.lock
9+
*.bs.js

examples/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 ReScript Brazil
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

examples/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# ES2077 :: Vite ReScript Template
2+
3+
## Getting started 🚀
4+
5+
Simply click on `Use this template` 😃

examples/bsconfig.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "vite-rescript-starter",
3+
"sources": [
4+
{
5+
"dir": "src",
6+
"subdirs": true
7+
}
8+
],
9+
"package-specs": [
10+
{
11+
"module": "es6",
12+
"in-source": true
13+
}
14+
],
15+
"reason": { "react-jsx": 3 },
16+
"suffix": ".bs.js",
17+
"bs-dependencies": [
18+
"@rescript/react",
19+
"@ryyppy/rescript-promise",
20+
"@rescriptbr/react-query"
21+
]
22+
}

examples/index.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/src/favicon.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>ReScript + Vite</title>
8+
<link rel="preconnect" href="https://fonts.googleapis.com">
9+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
10+
<link href="https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;700&display=swap" rel="stylesheet">
11+
</head>
12+
<body>
13+
<div id="root"></div>
14+
<script type="module" src="/src/main.jsx"></script>
15+
</body>
16+
</html>

examples/package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "vite-rescript-template",
3+
"version": "0.0.1",
4+
"scripts": {
5+
"dev": "vite",
6+
"build": "vite build",
7+
"serve": "vite preview",
8+
"rescript:build": "rescript",
9+
"rescript:start": "rescript build -w"
10+
},
11+
"dependencies": {
12+
"@rescript/react": "0.10.3",
13+
"@rescriptbr/react-query": "../",
14+
"@ryyppy/rescript-promise": "2.1.0",
15+
"@vitejs/plugin-react": "1.0.1",
16+
"react": "17.0.0",
17+
"react-dom": "17.0.0",
18+
"react-query": "^3.25.0",
19+
"rescript": "9.1.4",
20+
"web-vitals": "2.0.1"
21+
},
22+
"devDependencies": {
23+
"vite": "2.3.8"
24+
}
25+
}

examples/src/App.res

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
module Fetch = {
2+
type response
3+
4+
@send external json: response => Js.Promise.t<'a> = "json"
5+
@val external fetch: (string, {..}) => Js.Promise.t<response> = "fetch"
6+
}
7+
8+
type todo = {id: string, title: string}
9+
10+
let apiUrl = "https://jsonplaceholder.typicode.com/todos/1"
11+
let client = ReactQuery.Provider.createClient()
12+
13+
let fetchTodos = (_): Js.Promise.t<todo> => {
14+
let {then} = module(Promise)
15+
16+
Fetch.fetch(
17+
apiUrl,
18+
{
19+
"method": "GET",
20+
},
21+
)->then(Fetch.json)
22+
}
23+
24+
module TodoItem = {
25+
let {useQuery, queryOptions} = module(ReactQuery)
26+
27+
@react.component
28+
let make = () => {
29+
let queryResult = useQuery(
30+
queryOptions(
31+
~queryFn=fetchTodos,
32+
~queryKey="todos",
33+
~refetchOnWindowFocus=ReactQuery.refetchOnWindowFocus(#bool(false)),
34+
(),
35+
),
36+
)
37+
38+
<div>
39+
{switch queryResult {
40+
| {isLoading: true} => "Loading..."->React.string
41+
| {data: Some(todo)} => `Todo Title ${todo.title}`->React.string
42+
| _ => `Unexpected error...`->React.string
43+
}}
44+
</div>
45+
}
46+
}
47+
48+
@react.component
49+
let make = () => {
50+
<ReactQuery.Provider client>
51+
<div> <h1> {React.string("ReScript + React Query")} </h1> <TodoItem /> </div>
52+
</ReactQuery.Provider>
53+
}

examples/src/Main.res

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
let root = ReactDOM.querySelector("#root")
2+
3+
let () = switch root {
4+
| Some(element) => ReactDOM.render(<React.StrictMode> <App /> </React.StrictMode>, element)
5+
| None => Js.Exn.raiseError("Root not found!")
6+
}

examples/src/main.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
html, body, #root {
2+
padding: 0;
3+
margin: 0;
4+
background: #fafafa;
5+
}
6+
7+
* {
8+
font-family: 'DM Sans', sans-serif;
9+
}
10+
11+
.main-container {
12+
text-align: center;
13+
color: #373737;
14+
}

0 commit comments

Comments
 (0)