Skip to content

Commit 12d2099

Browse files
authored
Merge pull request #7 from goransh/feature/cleanup-for-release
Feature/cleanup for release
2 parents b016d2f + fda5b93 commit 12d2099

17 files changed

+27479
-14375
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
## 1.0.1
4+
_18 December 2021_
5+
6+
* Fix publish error
7+
8+
## 1.0.0
9+
_18 December 2021_
10+
11+
* **Breaking change**: Removed the `interceptors` feature that was deprecated in version 0.2.1. [Read more about this here](https://github.com/goransh/react-super-context/wiki/Interceptors-deprecated).
12+
* Updated naming convention of the context objects/functions to use PascalCase (like a component) instead of camelCase in readme and examples
313

414
## 0.2.2
515
_9 April 2021_

README.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# react-super-context
22

3-
A tiny wrapper library around the React Context API that reduces the amount of boilerplate code required to create and consume contexts.
3+
A tiny wrapper library around the [React Context API](https://reactjs.org/docs/context.html) that removes a lot of boilerplate required to create and consume contexts.
44

55
## Features
66

@@ -55,7 +55,7 @@ export const useCounter = () => useContext(CounterContext);
5555
### After
5656
```typescript jsx
5757
// createSuperContext returns a custom provider and a hook for consumption
58-
const [counterContext, useCounter] = createSuperContext(() => {
58+
const [CounterContext, useCounter] = createSuperContext(() => {
5959
// the state logic is the same as before
6060
const [count, setCount] = useState(0);
6161
const increment = () => setCount(count + 1);
@@ -66,7 +66,7 @@ const [counterContext, useCounter] = createSuperContext(() => {
6666
return { count, increment, decrement };
6767
});
6868

69-
export { counterContext, useCounter };
69+
export { CounterContext, useCounter };
7070
```
7171

7272
### Before
@@ -87,7 +87,7 @@ const App = () => {
8787
### After
8888
```typescript jsx
8989
const App = () => (
90-
<SuperContext contexts={[counterContext, mySecondContext, myThirdContext]}>
90+
<SuperContext contexts={[CounterContext, MySecondContext, MyThirdContext]}>
9191
<div>Your app with consumers comes here</div>
9292
</SuperContext>
9393
);
@@ -100,18 +100,18 @@ const App = () => (
100100
**1**. Use the `createSuperContext` function to create your context. It takes a factory function that returns the context's value and returns a context object as well as a hook to consume the state.
101101
```javascript
102102
// CounterContext.ts
103-
const [counterContext, useCounter] = createSuperContext(() => {
103+
const [CounterContext, useCounter] = createSuperContext(() => {
104104
const [count, setCount] = useState(0);
105105
return {count, setCount};
106106
});
107107

108-
export {counterContext, useCounter };
108+
export { CounterContext, useCounter };
109109
```
110-
**2**. To create a provider for the context, add the `SuperContext` component in your app and pass it the `counterContext` created by the `createSuperContext` call.
110+
**2**. To create a provider for the context, add the `SuperContext` component in your app and pass it the `CounterContext` created by the `createSuperContext` call.
111111
```typescript jsx
112112
// App.tsx
113113
const App = () => (
114-
<SuperContext contexts={[counterContext]}>
114+
<SuperContext contexts={[CounterContext]}>
115115
<CountDisplay/>
116116
<CounterButton/>
117117
</SuperContext>
@@ -139,26 +139,26 @@ const CounterButton = () => {
139139

140140
```javascript
141141
// EvenOrOddContext.ts
142-
const [evenOrOddContext, useEvenOrOdd] = createSuperContext(() => {
142+
const [EvenOrOddContext, useEvenOrOdd] = createSuperContext(() => {
143143
const { count } = useCounter();
144144
return count % 2 === 0 ? "even" : "odd";
145145
});
146146

147-
export { evenOrOddContext, useEvenOrOdd };
147+
export { EvenOrOddContext, useEvenOrOdd };
148148
```
149149

150150
**2**. Remember to add it to the contexts lists. The order of the contexts matters.
151151
```typescript jsx
152152
// App.tsx
153153
const App = () => (
154-
<SuperContext contexts={[counterContext, evenOrOddContext]}>
154+
<SuperContext contexts={[CounterContext, EvenOrOddContext]}>
155155
<CountDisplay/>
156156
<CounterButton/>
157157
</SuperContext>
158158
);
159159
```
160160

161-
`evenOrOddContext` depends on `counterContext` so if they were given the other way around (`contexts={[evenOrOddContext, counterContext]}`), then the `useCounter` call in `EvenOrOddContext.ts` will throw an error.
161+
`EvenOrOddContext` depends on `CounterContext` so if they were given the other way around (`contexts={[EvenOrOddContext, CounterContext]}`), then the `useCounter` call in `EvenOrOddContext.ts` will throw an error.
162162

163163
**3**. Consume the new context.
164164

@@ -174,7 +174,7 @@ export const CountDisplay = () => {
174174

175175
### 3. Use hooks as you normally would
176176
```typescript jsx
177-
const [logging] = createSuperContext(() => {
177+
const [Logging] = createSuperContext(() => {
178178
const { count } = useCounter();
179179
const evenOrOdd = useEvenOrOdd();
180180

@@ -183,7 +183,7 @@ const [logging] = createSuperContext(() => {
183183
}, [count, evenOrOdd]);
184184
});
185185

186-
export default logging;
186+
export default Logging;
187187
```
188188

189189
Remember to always add your context objects to the `SuperContext` component.
@@ -198,20 +198,20 @@ interface CounterContextProps {
198198
initial: number;
199199
}
200200

201-
const [counterContext, useCounter] = createSuperContext(({ initial }: CounterContextProps) => {
201+
const [CounterContext, useCounter] = createSuperContext(({ initial }: CounterContextProps) => {
202202
const [count, setCount] = useState(initial);
203203
return { count, setCount };
204204
});
205205

206-
export {counterContext, useCounter };
206+
export { CounterContext, useCounter };
207207
```
208208
209-
**2**. `counter` is a function that you can pass the props to.
209+
**2**. `CounterContext` is a function that you can pass the props to.
210210
211211
```javascript
212212
// App.tsx
213213
const App = () => (
214-
<SuperContext contexts={[counter({ initial: 10 })]}>
214+
<SuperContext contexts={[CounterContext({ initial: 10 })]}>
215215
<CountDisplay/>
216216
<CounterButton/>
217217
</SuperContext>
@@ -236,13 +236,13 @@ However, you can also define types explicitly:
236236
**1**. Type given explicitly in `createSuperContext` call.
237237
```typescript
238238
// CounterContext.ts
239-
interface CounterContext {
239+
interface CounterContextModel {
240240
count: number;
241241
increment: () => void;
242242
decrement: () => void;
243243
}
244244
245-
const [counter, useCounter] = createSuperContext<CounterContext>(() => {
245+
const [CounterContext, useCounter] = createSuperContext<CounterContextModel>(() => {
246246
const [count, setCount] = useState(0);
247247
const increment = () => setCount(count + 1);
248248
const decrement = () => setCount(Math.max(0, count - 1));
@@ -268,15 +268,15 @@ interface CounterContextProps {
268268
initial: number;
269269
}
270270

271-
const [counterContext, useCounter] = createSuperContext(({ initial }: CounterContextProps) => {
271+
const [CounterContext, useCounter] = createSuperContext(({ initial }: CounterContextProps) => {
272272
const [count, setCount] = useState(initial);
273273
return { count, setCount };
274274
});
275275
```
276276
277277
If you have defined the context's value type explicitly, you must pass the prop type as the second generic argument (at least [until TypeScript gets support for partial type argument inference](https://github.com/microsoft/TypeScript/issues/26242)).
278278
```typescript
279-
const [counter, useCounter] = createSuperContext<CounterContext, CounterContextProps>(({initial}) => {
279+
const [CounterContext, useCounter] = createSuperContext<CounterContext, CounterContextProps>(({initial}) => {
280280
const [count, setCount] = useState(initial);
281281
return { count, setCount };
282282
});
@@ -287,7 +287,7 @@ const [counter, useCounter] = createSuperContext<CounterContext, CounterContextP
287287
The `createSuperContext` function takes an optional object as the second argument, allowing you to specify a number of options.
288288
289289
```typescript
290-
const [counterContext, useCounter] = createSuperContext(
290+
const [CounterContext, useCounter] = createSuperContext(
291291
() => {
292292
const [count, setCount] = useState(0);
293293
return { count, setCount };
@@ -306,14 +306,14 @@ If you use many of the same options on all context provided by a `SuperContext`,
306306
```typescript jsx
307307
const App = () => (
308308
<SuperContext
309-
contexts={[counterContext, evenOrOddContext]}
309+
contexts={[CounterContext, EvenOrOddContext]}
310310
defaultOptions={{displayName: "MyContext"}}
311311
>...</SuperContext>
312312
);
313313
```
314314
315-
In the example above, both the `counterContext` and the `evenOrOddContext` provider components will be displayed as "MyContext" in error messages.
315+
In the example above, both the `CounterContext` and the `EvenOrOddContext` provider components will be displayed as "MyContext" in error messages.
316316
317317
### More examples
318318
319-
[See full examples here.](https://github.com/goransh/react-super-context/tree/master/example/src)
319+
[See complete examples here.](https://github.com/goransh/react-super-context/tree/master/example/src)

0 commit comments

Comments
 (0)