Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: react hooks observers #1127

Merged
merged 12 commits into from
Mar 11, 2024
Merged
5 changes: 5 additions & 0 deletions .changeset/lucky-ants-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@fuel-wallet/react': minor
---

fix: fuel hooks will only re-render tracked properties, instead of listening to every useQuery property.
60 changes: 22 additions & 38 deletions examples/cra-dapp/README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,30 @@
# Getting Started with Create React App
# React + TypeScript + Vite

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

## Available Scripts
Currently, two official plugins are available:

In the project directory, you can run:
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

### `npm start`
## Expanding the ESLint configuration

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

The page will reload if you make edits.\
You will also see any lint errors in the console.
- Configure the top-level `parserOptions` property like this:

### `npm test`
```js
export default {
// other rules...
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
};
```

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).
- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
12 changes: 12 additions & 0 deletions examples/cra-dapp/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Fuel Wallet Example</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
38 changes: 13 additions & 25 deletions examples/cra-dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,20 @@
"name": "cra-dapp",
"version": "0.1.0",
"private": true,
"dependencies": {
"@fuels/react": "0.15.1",
"@types/node": "^16.18.61",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"fuels": "0.67.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"typescript": "^4.9.5",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"eject": "react-scripts eject"
"start": "vite"
},
"dependencies": {
"@fuel-wallet/react": "workspace:*",
"fuels": "0.74.0",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
"devDependencies": {
"@types/react": "18.2.56",
"@types/react-dom": "18.2.19",
"@vitejs/plugin-react": "4.2.1",
"typescript": "5.2.2",
"vite": "5.1.4"
}
}
Binary file removed examples/cra-dapp/public/favicon.ico
Binary file not shown.
43 changes: 0 additions & 43 deletions examples/cra-dapp/public/index.html

This file was deleted.

15 changes: 0 additions & 15 deletions examples/cra-dapp/public/manifest.json

This file was deleted.

3 changes: 0 additions & 3 deletions examples/cra-dapp/public/robots.txt

This file was deleted.

2 changes: 1 addition & 1 deletion examples/cra-dapp/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
useDisconnect,
useConnectUI,
useIsConnected,
} from '@fuels/react';
} from '@fuel-wallet/react';
import './App.css';

function App() {
Expand Down
8 changes: 0 additions & 8 deletions examples/cra-dapp/src/index.css

This file was deleted.

29 changes: 0 additions & 29 deletions examples/cra-dapp/src/index.tsx

This file was deleted.

13 changes: 13 additions & 0 deletions examples/cra-dapp/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { FuelProvider } from '@fuel-wallet/react';
import React from 'react';
import ReactDOM from 'react-dom/client';

import App from './App';

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<React.StrictMode>
<FuelProvider>
<App />
</FuelProvider>
</React.StrictMode>
);
1 change: 0 additions & 1 deletion examples/cra-dapp/src/react-app-env.d.ts

This file was deleted.

15 changes: 0 additions & 15 deletions examples/cra-dapp/src/reportWebVitals.ts

This file was deleted.

1 change: 1 addition & 0 deletions examples/cra-dapp/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
29 changes: 17 additions & 12 deletions examples/cra-dapp/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
"jsx": "react-jsx",

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"]
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
11 changes: 11 additions & 0 deletions examples/cra-dapp/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true,
"strict": true
},
"include": ["vite.config.ts"]
}
7 changes: 7 additions & 0 deletions examples/cra-dapp/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
});
18 changes: 6 additions & 12 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,23 @@
"description": "Interact with the Fuel Wallet Extension in React.",
"version": "0.15.2",
"license": "Apache-2.0",
"main": "src/index.ts",
"main": "./src/index.ts",
"exports": {
".": {
"require": "./dist/index.js",
"default": "./dist/index.mjs"
}
".": "./src/index.ts"
},
"publishConfig": {
"access": "public",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"typings": "dist/index.d.ts",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"typings": "./dist/index.d.ts",
"exports": {
".": {
"require": "./dist/index.js",
"default": "./dist/index.mjs"
}
}
},
"files": [
"dist"
],
"scripts": {
"build": "pnpm ts:check && tsup",
"ts:check": "pnpm tsc --noEmit"
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/core/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './useNamedQuery';
Loading
Loading