Skip to content

Commit

Permalink
refactor: change configuration file (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
alamenai authored Jun 9, 2024
1 parent bcb40ba commit 2eb881c
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 63 deletions.
38 changes: 19 additions & 19 deletions .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
name: Lint and Test

on:
pull_request:
branches: [dev]
pull_request:
branches: [dev]

jobs:
lint-and-test:
runs-on: ubuntu-latest
lint-and-test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x, 16.x,22.x]
strategy:
matrix:
node-version: [14.x, 16.x, 22.x]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm install
- name: Run ESLint
run: npm run lint
- name: Run Tests
run: npm test
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm install
- name: Run ESLint
run: npm run lint
- name: Run Tests
run: npm test
39 changes: 13 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,18 @@

</div>


## Hooks

| Hook Name | Description |
|---------------------|-----------------------------------------------------------|
| [`useAbortController`](https://www.rehook.dev/hooks/use-abort-controller) | A custom hook for managing operations with an AbortController instance. This hook provides functionalities for aborting operations, checking if aborted, and managing abort conditions.|
| [`useBattery`](https://www.rehook.dev/hooks/use-battery) | A custom hook for fetching battery status information.|
| [`useFetch`](https://www.rehook.dev/hooks/use-fetch) | A custom hook for fetching data from an API.|
| [`useHistory`](https://www.rehook.dev/hooks/use-history) | A custom hook for managing browser history navigation.|
| [`useLoading`](https://www.rehook.dev/hooks/use-loading) | A custom hook that provides functionalities for managing loading state.|
| [`useLoading`](https://www.rehook.dev/hooks/use-loading) | A custom hook that provides functionalities for managing loading state.|
| [`useLocalStorage`](https://www.rehook.dev/hooks/use-local-storage) | A custom hook that provides functionalities for managing data in the browser's local storage.|
| [`usePersistentState`](https://www.rehook.dev/hooks/use-persistent-state) | A custom hook that provides persistent state management by storing state values in the browser's local storage.|
| [`useQueryParams`](https://www.rehook.dev/hooks/use-query-params) | A custom hook that provides functionalities for managing query parameters in the URL.|
| [`useTimeout`](https://www.rehook.dev/hooks/use-timeout) | A custom hook for managing timeouts.|
| [`useUrl`](https://www.rehook.dev/hooks/use-url) | A custom hook for accessing URL information.|












| Hook Name | Description |
| ------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`useAbortController`](https://www.rehook.dev/hooks/use-abort-controller) | A custom hook for managing operations with an AbortController instance. This hook provides functionalities for aborting operations, checking if aborted, and managing abort conditions. |
| [`useBattery`](https://www.rehook.dev/hooks/use-battery) | A custom hook for fetching battery status information. |
| [`useFetch`](https://www.rehook.dev/hooks/use-fetch) | A custom hook for fetching data from an API. |
| [`useHistory`](https://www.rehook.dev/hooks/use-history) | A custom hook for managing browser history navigation. |
| [`useLoading`](https://www.rehook.dev/hooks/use-loading) | A custom hook that provides functionalities for managing loading state. |
| [`useLoading`](https://www.rehook.dev/hooks/use-loading) | A custom hook that provides functionalities for managing loading state. |
| [`useLocalStorage`](https://www.rehook.dev/hooks/use-local-storage) | A custom hook that provides functionalities for managing data in the browser's local storage. |
| [`usePersistentState`](https://www.rehook.dev/hooks/use-persistent-state) | A custom hook that provides persistent state management by storing state values in the browser's local storage. |
| [`useQueryParams`](https://www.rehook.dev/hooks/use-query-params) | A custom hook that provides functionalities for managing query parameters in the URL. |
| [`useTimeout`](https://www.rehook.dev/hooks/use-timeout) | A custom hook for managing timeouts. |
| [`useUrl`](https://www.rehook.dev/hooks/use-url) | A custom hook for accessing URL information. |
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"lint-staged": "^15.2.0",
"prettier": "3.0.3",
"typescript": "^5.3.3",
"vite": "^4.5.3"
"vite": "^4.5.3",
"vitest": "^1.6.0"
}
}
13 changes: 13 additions & 0 deletions rehook.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const VITE_DEFAULT_ENV_VARS = ['BASE_URL', 'NODE', 'MODE', 'DEV', 'PROD', 'SSR']

export const NEXT_DEFAULT_ENV_VARS = ['NODE_ENV', 'TZ']

type RehookConfig = {
framework: 'VITE' | 'NEXT'
ignoreDefaultEnv: boolean
}

export const rehookConfig: RehookConfig = {
framework: 'VITE',
ignoreDefaultEnv: true,
}
21 changes: 10 additions & 11 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import './App.css';
import { useQueryParams } from './hooks/useQueryParams';
import './App.css'
import { useQueryParams } from './hooks/useQueryParams'
// import reactLogo from './assets/react.svg';
import viteLogo from '/vite.svg';
import { useState } from 'react';
import { useState } from 'react'

function App() {
const [count, setCount] = useState(0);
const { get, set } = useQueryParams();
const [count, setCount] = useState(0)
const { get, set } = useQueryParams()
const handleClick = () => {
set('page', '2');
};
set('page', '2')
}

return (
<>
<div>
<p>Current page: {get('page') || 'N/A'}</p>
<button onClick={handleClick}>Go to page 2</button>
</div>
</div>
<div>
<a href="https://vitejs.dev" target="_blank">
{/* <img src={viteLogo} className="logo" alt="Vite logo" /> */}
Expand All @@ -34,7 +33,7 @@ function App() {
</div>
<p className="read-the-docs">Click on the Vite and React logos to learn more</p>
</>
);
)
}

export default App;
export default App
7 changes: 3 additions & 4 deletions src/actions/env.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
'use server'

import { NEXT_DEFAULT_ENV_VARS, VITE_DEFAULT_ENV_VARS } from '../constants/env'
import { rehookConfig } from '../rehook.config'
import { NEXT_DEFAULT_ENV_VARS, VITE_DEFAULT_ENV_VARS, rehookConfig } from '../../rehook.config'

const { ignoreDefaultEnv, framework } = rehookConfig

const isFrameworkVite = framework === 'VITE' // Otherwise it is NEXTJS

export const getEnv = async () => {
const variables = Object.keys(isFrameworkVite ? import.meta.env : process.env)
const variables = isFrameworkVite ? import.meta.env : process.env

if (ignoreDefaultEnv) {
const filteredVariables = variables.filter(variable =>
const filteredVariables = variables.filter((variable: string) =>
isFrameworkVite ? !VITE_DEFAULT_ENV_VARS.includes(variable) : !NEXT_DEFAULT_ENV_VARS.includes(variable),
)
return filteredVariables
Expand Down
3 changes: 1 addition & 2 deletions src/hooks/use-env.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { NEXT_DEFAULT_ENV_VARS, VITE_DEFAULT_ENV_VARS } from '../constants/env'
import { rehookConfig } from '../rehook.config'
import { NEXT_DEFAULT_ENV_VARS, VITE_DEFAULT_ENV_VARS, rehookConfig } from '../../rehook.config'
import { useEffect, useState } from 'react'

const { ignoreDefaultEnv, framework } = rehookConfig
Expand Down

0 comments on commit 2eb881c

Please sign in to comment.