Skip to content

Commit 209a74f

Browse files
author
Niels Peschel
committed
add files
1 parent 3f62dec commit 209a74f

34 files changed

+5813
-79
lines changed

.github/PULL_REQUEST_TEMPLATE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ _Put an `x` in the boxes that apply_
1515

1616
_Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code._
1717

18-
- [ ] I have read the [CONTRIBUTING](https://github.com/Optum/oss-template/blob/main/CONTRIBUTING.md) doc
18+
- [ ] I have read the [CONTRIBUTING](../CONTRIBUTING.md) doc
1919
- [ ] I have added tests that prove my fix is effective or that my feature works
2020
- [ ] I have added necessary documentation (if appropriate)
2121
- [ ] Any dependent changes have been merged and published in downstream modules

.gitignore

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#VS Code
2+
.vscode/*
3+
!.vscode/settings.json
4+
!.vscode/tasks.json
5+
!.vscode/extensions.json
6+
7+
# Logs
8+
logs
9+
*.log
10+
npm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
package-lock.json
14+
lerna-debug.log*
15+
16+
# Coverage directory used by tools like istanbul
17+
coverage
18+
19+
# Dependency directories
20+
node_modules/
21+
22+
#report
23+
.scannerwork/
24+
.history/
25+
.idea
26+
reports/
27+
lhci-data/
28+
29+
# misc
30+
.DS_Store
31+
32+
# Build Output
33+
build/
34+
.jest-test-results.json
35+
storybook-static/
36+
gh-build/
37+
.nyc_output/
38+
39+
# https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored
40+
.yarn/*
41+
!.yarn/cache
42+
!.yarn/releases
43+
!.yarn/plugins
44+
!.yarn/sdks
45+
!.yarn/versions
46+
.pnp.*
47+
48+
.yalc/
49+
yalc.lock
50+
51+
packages/**/*.jsx
52+
packages/**/*.js.map
53+
packages/**/*.jsx.map
54+
packages/**/*.d.ts
55+
packages/scl-authenticated-proxy/logs
56+
.scannerwork/
57+
.history
58+
packages/client/themes/tmp/

NOTICE.txt

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
<Insert Project Name Here>
1+
react-hooks
22
Copyright 2022 Optum
33

44
Project Description:
55
====================
6-
<Short description of your project>
6+
A reusable set of React hooks.
77

88
Author(s):
9-
<List the names and GitHub IDs of the original project authors>
9+
Niels Peschel: NielsJPeschel
10+
Nicholas Thurow: nthurow

README.md

+82-75
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,21 @@
2525
<!-- PROJECT LOGO -->
2626
<br />
2727
<div align="center">
28-
<a href="https://github.com/github_username/repo_name">
28+
<a href="https://github.com/optum/react-hooks">
2929
<img src="images/logo.png" alt="Logo" width="80" height="80">
3030
</a>
3131

32-
<h3 align="center">project_title</h3>
32+
<h3 align="center">react-hooks</h3>
3333

3434
<p align="center">
35-
project_description
35+
A reusable set of React hooks.
3636
<br />
37-
<a href="https://github.com/github_username/repo_name"><strong>Explore the docs »</strong></a>
37+
<a href="https://github.com/optum/react-hooks"><strong>Explore the docs »</strong></a>
3838
<br />
3939
<br />
40-
<a href="https://github.com/github_username/repo_name">View Demo</a>
40+
<a href="https://github.com/optum/react-hooks/issues">Report Bug</a>
4141
·
42-
<a href="https://github.com/github_username/repo_name/issues">Report Bug</a>
43-
·
44-
<a href="https://github.com/github_username/repo_name/issues">Request Feature</a>
42+
<a href="https://github.com/optum/react-hooks/issues">Request Feature</a>
4543
</p>
4644
</div>
4745

@@ -78,83 +76,94 @@
7876
<!-- ABOUT THE PROJECT -->
7977
## About The Project
8078

81-
[![Product Name Screen Shot][product-screenshot]](https://example.com)
82-
83-
Here's a blank template to get started: To avoid retyping too much info. Do a search and replace with your text editor for the following: `github_username`, `repo_name`, `twitter_handle`, `linkedin_username`, `email`, `email_client`, `project_title`, `project_description`
79+
This repository contains various reusable hooks built and currently being used throughout [Optum](https://optum.com). They were created with the goal of simplifying otherwise complex react procedures and concepts, such as state management of asynchronous data, accessibility, etc. Please feel free to explore this repository and use, contribute, and add to these hooks!
8480

8581
<p align="right">(<a href="#top">back to top</a>)</p>
8682

83+
<!-- GETTING STARTED -->
84+
## Getting Started
85+
Currently, `react-hooks` is not published in `npm`. Please see [Test Changes Locally](#test-locally) for a way to run our hooks locally
8786

87+
### Prerequisites
88+
Have desired javascript package mananger installed on your machine:
8889

89-
### Built With
90-
91-
* [Next.js](https://nextjs.org/)
92-
* [React.js](https://reactjs.org/)
93-
* [Vue.js](https://vuejs.org/)
94-
* [Angular](https://angular.io/)
95-
* [Svelte](https://svelte.dev/)
96-
* [Laravel](https://laravel.com)
97-
* [Bootstrap](https://getbootstrap.com)
98-
* [JQuery](https://jquery.com)
99-
100-
<p align="right">(<a href="#top">back to top</a>)</p>
101-
102-
90+
* [yarn](https://classic.yarnpkg.com/lang/en/docs/install/#mac-stable)
91+
* preferred but not required
10392

104-
<!-- GETTING STARTED -->
105-
## Getting Started
93+
or
94+
* [npm](https://www.npmjs.com/package/npm)
10695

107-
This is an example of how you may give instructions on setting up your project locally.
108-
To get a local copy up and running follow these simple example steps.
10996

110-
### Prerequisites
97+
**Optional**
98+
* [yalc](https://github.com/wclr/yalc)
99+
* used for testing package locally
111100

112-
This is an example of how to list things you need to use the software and how to install them.
113-
* npm
114-
```sh
115-
npm install npm@latest -g
116-
```
117101

118102
### Installation
119-
120-
1. Get a free API Key at [https://example.com](https://example.com)
121-
2. Clone the repo
103+
Currently, this package is not published and can therefore not be installed by conventional means (_yarn_ or _npm_). Please see next section if you still wish to utilize this pacakge locally
104+
<!-- 1. Clone the repo
122105
```sh
123-
git clone https://github.com/github_username/repo_name.git
106+
git clone https://github.com/optum/react-hooks.git
124107
```
125-
3. Install NPM packages
108+
2. Install NPM packages
126109
```sh
127-
npm install
128-
```
129-
4. Enter your API in `config.js`
130-
```js
131-
const API_KEY = 'ENTER YOUR API';
132-
```
110+
yarn install
111+
``` -->
133112

134113
<p align="right">(<a href="#top">back to top</a>)</p>
135114

115+
<div id='test-locally'>
116+
### Testing Changes Locally
117+
If you are in the process of making changes to this repo and wish to test them, or simply wish to playground with our hooks:
118+
119+
1. Have a working react project
120+
2. Have [yalc](https://github.com/wclr/yalc) installed globally
121+
```sh
122+
yarn global add yalc
123+
```
124+
3. Inside `react-hooks` directory, publish package to yalc store
125+
```sh
126+
yalc publish
127+
```
128+
4. Inside of directory of your project, add package
129+
```sh
130+
yalc add react-hooks
131+
```
132+
5. As you make changes inside of `react-hooks`, continue publishing to store, as explained in step 3.
133+
6. Update yalc store inside of project directory after each new publish (this may require stopping running instances of project)
134+
```sh
135+
yalc update
136+
```
137+
7. Once finished, remove yalc package from project directory
138+
```sh
139+
yalc remove react-hooks
140+
```
141+
or
142+
```sh
143+
yalc remove --all
144+
```
145+
(if you wish to remove other yalc packages)
136146

137147

138-
<!-- USAGE EXAMPLES -->
139-
## Usage
140148

141-
Use this space to show useful examples of how a project can be used. Additional screenshots, code examples and demos work well in this space. You may also link to more resources.
149+
<p align="right">(<a href="#top">back to top</a>)</p>
142150

143-
_For more examples, please refer to the [Documentation](https://example.com)_
151+
<!-- USAGE EXAMPLES -->
152+
## Usage
153+
Please refer to directories inside of `/hooks` for usages of individual hooks.
144154

145155
<p align="right">(<a href="#top">back to top</a>)</p>
146156

147157

148158

149159
<!-- ROADMAP -->
150160
## Roadmap
151-
161+
<!--
152162
- [] Feature 1
153163
- [] Feature 2
154164
- [] Feature 3
155-
- [] Nested Feature
156-
157-
See the [open issues](https://github.com/github_username/repo_name/issues) for a full list of proposed features (and known issues).
165+
- [] Nested Feature -->
166+
See the [open issues](https://github.com/optum/react-hooks/issues) for a full list of proposed features (and known issues).
158167

159168
<p align="right">(<a href="#top">back to top</a>)</p>
160169

@@ -190,40 +199,38 @@ Distributed under the Apache 2.0 License. See `LICENSE.txt` for more information
190199
<!-- MAINTAINERS -->
191200
## Maintainers
192201

193-
- Full Name 1
194-
- GitHub Enterprise: [github_username](https://github.com/username1)
195-
- Email: email1@email.com
196-
- Full Name 2
197-
- GitHub Enterprise: [github_username](https://github.com/username2)
198-
202+
- Niels Peschel
203+
- GitHub: [NielsJPeschel](https://github.com/NielsJPeschel)
204+
- Email: peschel.niels@gmail.com
205+
- Nicholas Thurow
206+
- GitHub: [nthurow](https://github.com/nthurow)
207+
<!-- - Email: [email protected] -->
199208

200209
<p align="right">(<a href="#top">back to top</a>)</p>
201210

202-
203-
204211
<!-- ACKNOWLEDGMENTS -->
205-
## Acknowledgments
212+
<!-- ## Acknowledgments
206213
207214
* []()
208215
* []()
209216
* []()
210217
211-
<p align="right">(<a href="#top">back to top</a>)</p>
218+
<p align="right">(<a href="#top">back to top</a>)</p> -->
212219

213220

214221

215222
<!-- MARKDOWN LINKS & IMAGES -->
216223
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->
217-
[contributors-shield]: https://img.shields.io/github/contributors/github_username/repo_name.svg?style=for-the-badge
218-
[contributors-url]: https://github.com/github_username/repo_name/graphs/contributors
219-
[forks-shield]: https://img.shields.io/github/forks/github_username/repo_name.svg?style=for-the-badge
220-
[forks-url]: https://github.com/github_username/repo_name/network/members
221-
[stars-shield]: https://img.shields.io/github/stars/github_username/repo_name.svg?style=for-the-badge
222-
[stars-url]: https://github.com/github_username/repo_name/stargazers
223-
[issues-shield]: https://img.shields.io/github/issues/github_username/repo_name.svg?style=for-the-badge
224-
[issues-url]: https://github.com/github_username/repo_name/issues
225-
[license-shield]: https://img.shields.io/github/license/github_username/repo_name.svg?style=for-the-badge
226-
[license-url]: https://github.com/github_username/repo_name/blob/master/LICENSE.txt
224+
[contributors-shield]: https://img.shields.io/github/contributors/optum/react-hooks.svg?style=for-the-badge
225+
[contributors-url]: https://github.com/optum/react-hooks/graphs/contributors
226+
[forks-shield]: https://img.shields.io/github/forks/optum/react-hooks.svg?style=for-the-badge
227+
[forks-url]: https://github.com/optum/react-hooks/network/members
228+
[stars-shield]: https://img.shields.io/github/stars/optum/react-hooks.svg?style=for-the-badge
229+
[stars-url]: https://github.com/optum/react-hooks/stargazers
230+
[issues-shield]: https://img.shields.io/github/issues/optum/react-hooks.svg?style=for-the-badge
231+
[issues-url]: https://github.com/optum/react-hooks/issues
232+
[license-shield]: https://img.shields.io/github/license/optum/react-hooks.svg?style=for-the-badge
233+
[license-url]: https://github.com/optum/react-hooks/blob/master/LICENSE.txt
227234
[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge&logo=linkedin&colorB=555
228-
[linkedin-url]: https://linkedin.com/in/linkedin_username
235+
[linkedin-url]: https://linkedin.com/in/niels-peschel
229236
[product-screenshot]: images/screenshot.png

babel.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
presets: [
3+
['@babel/preset-env', {targets: {node: 'current'}}],
4+
'@babel/preset-typescript'
5+
],
6+
};

hooks/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export * from './useLoadData';
2+
export * from './useCommonContext';
3+
export * from './useFocus';
4+
export * from './useRetry';
5+
export * from './useServiceEffect';

hooks/useCommonContext/README.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# `useCommonContext`
2+
3+
A React hook that allows connecting to several potential active react contexts.
4+
5+
## Usage
6+
`useCommonContext` is designed to be used in tandem with **React context**. If a component is being used in a variety of locations that each are serving a different context (of the same type):
7+
8+
9+
```Typescript
10+
import React from 'react';
11+
import {useCommonContext} from 'react-hooks';
12+
13+
import {useContextA} from 'some-context-provider-a';
14+
import {useContextB} from 'some-context-provider-b';
15+
import {useContextC} from 'some-context-provider-c';
16+
17+
18+
export const MyComponent = (props) => {
19+
const context = useCommonContext(useContextA, useContextB, useContextC);
20+
21+
return ...
22+
}
23+
```
24+
25+
## API
26+
27+
`useCommonContext` takes the following arguments:
28+
29+
| Name | Type | Description |
30+
|-|-|-|
31+
| `...contextHook` | `(() => T)[]` | any number of contexts with return type, `T` |
32+
33+
34+
The return value of `useCommonContext` is `T`.
35+
36+
**Note: `useCommonContext` is designed to be used where only one of the passed contexts is active. Passing several active contexts will result in the last passed context being used. If no context is active, an error will be thrown**

hooks/useCommonContext/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './useCommonContext';
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export function useCommonContext<T>(...contextHooks: (() => T)[]): T {
2+
const context = contextHooks.reduce((prev, useContext) => {
3+
try {
4+
return useContext();
5+
} catch {
6+
return prev;
7+
}
8+
}, undefined as T | undefined);
9+
10+
if (!context) {
11+
throw new Error('contexts not available');
12+
}
13+
14+
return context;
15+
}

0 commit comments

Comments
 (0)