Skip to content

Commit b658bfc

Browse files
committed
No need to initialize context, we can safely assume the Consumer was properly wrapped in a Provider.
1 parent 3c021d5 commit b658bfc

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/index.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
import React from "react"
22

3-
const getInitialState = () => ({
4-
data: undefined,
5-
error: undefined,
6-
isLoading: false,
7-
startedAt: undefined,
8-
finishedAt: undefined
9-
})
10-
113
/**
124
* createInstance allows you to create instances of Async that are bound to a specific promise.
135
* A unique instance also uses its own React context for better nesting capability.
146
*/
157
export const createInstance = (defaultProps = {}) => {
16-
const { Consumer, Provider } = React.createContext(getInitialState())
8+
const { Consumer, Provider } = React.createContext()
179

1810
class Async extends React.Component {
1911
mounted = false
2012
counter = 0
2113
args = []
22-
state = getInitialState()
14+
state = {
15+
data: undefined,
16+
error: undefined,
17+
isLoading: false,
18+
startedAt: undefined,
19+
finishedAt: undefined
20+
}
2321

2422
componentDidMount() {
2523
this.mounted = true

0 commit comments

Comments
 (0)