Skip to content

Commit eb5efe2

Browse files
authored
v3.0.0-alpha.15
* feat(hooks): hook rework to match existing HOC - prescottprue#734 - @illuminist * fix(hooks): remove create functions (`createUseFirestore`, `createWithFirestore`, `createUseFirebase`, `createWithFirebase`) since store selection is not necessary * feat(auth): add custom claims - prescottprue#741 - @joerex * fix(types): changed extended firebase instance to function - prescottprue#743 - @rscotten * fix(types): switch `typeof Firebase` to `any` (prevents issue with passing some version of Firebase JS SDK) * fix(examples): update material and typescript examples
2 parents 9612d40 + bd834b7 commit eb5efe2

File tree

98 files changed

+16859
-22780
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+16859
-22780
lines changed

docs/api/constants.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ Default configuration options
146146
state (name given when passing reducer to combineReducers). Used in
147147
firebaseAuthIsReady promise (see
148148
[#264](https://github.com/prescottprue/react-redux-firebase/issues/264)).
149-
- `attachAuthIsReady` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `false` Whether or not to attach
149+
- `attachAuthIsReady` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `true` Whether or not to attach
150150
firebaseAuthIsReady to store. authIsLoaded can be imported and used
151151
directly instead based on preference.
152152
- `firestoreNamespace` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `firestoreHelpers` Namespace for

docs/api/useFirebase.md

+8-24
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,8 @@
22

33
### Table of Contents
44

5-
- [createUseFirebase](#createusefirebase)
65
- [useFirebase](#usefirebase)
76

8-
## createUseFirebase
9-
10-
Function that creates a react hook which provides `firebase` object.
11-
12-
**WARNING!!** This is an advanced feature, and should only be used when
13-
needing to access a firebase instance created under a different store key.
14-
Firebase state (`state.firebase`)
15-
16-
**Examples**
17-
18-
_Basic_
19-
20-
```javascript
21-
import { createUseFirebase } from 'react-redux-firebase'
22-
23-
// create useFirebase
24-
const useFirebase = createUseFirebase()
25-
```
26-
27-
Returns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** A hook fucntion that return firebase object.
28-
297
## useFirebase
308

319
React hook that provides `firebase` object.
@@ -44,14 +22,20 @@ import { useFirebase } from 'react-redux-firebase'
4422

4523
function AddData() {
4624
const firebase = useFirebase()
25+
26+
function addTodo() {
27+
const exampleTodo = { done: false, text: 'Sample' }
28+
return firebase.push('todos', exampleTodo)
29+
}
30+
4731
return (
4832
<div>
49-
<button onClick={() => firebase.push('todos', { done: false, text: 'Sample' })}>
33+
<button onClick={addTodo}>
5034
Add Sample Todo
5135
</button>
5236
</div>
5337
)
5438
}
5539
```
5640

57-
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Firebase instance
41+
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Extended Firebase instance

docs/api/useFirebaseConnect.md

+33-8
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ Returns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference
3030

3131
Hook that automatically listens/unListens
3232
to provided firebase paths using React's useEffect hook.
33-
**Note** Only single path is allowed per one hook
3433

3534
**Parameters**
3635

37-
- `queriesConfig` **([Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) \| [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String))** Object or string for path to sync
38-
from Firebase or null if hook doesn't need to sync.
39-
Can also be a function that returns an object or a path string.
36+
- `queriesConfigs` **([Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) \| [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array))** Object, string, or
37+
array contains object or string for path to sync from Firebase or null if
38+
hook doesn't need to sync. Can also be a function that returns an object,
39+
a path string, or array of an object or a path string.
4040

4141
**Examples**
4242

@@ -50,11 +50,11 @@ import { firebaseUseConnect } from 'react-redux-firebase'
5050
const enhance = compose(
5151
connect((state) => ({
5252
todos: state.firebase.ordered.todos
53-
})
53+
}))
5454
)
5555

5656
// use enhnace to pass todos list as props.todos
57-
const Todos = enhance(({ todos })) => {
57+
function Todos({ todos })) {
5858
useFirebaseConnect('todos') // sync /todos from firebase into redux
5959
return (
6060
<div>
@@ -76,10 +76,10 @@ import { firebaseUseConnect, getVal } from 'react-redux-firebase'
7676
const enhance = compose(
7777
connect((state, props) => ({
7878
post: getVal(state.firebase.data, `posts/${props.postId}`),
79-
})
79+
}))
8080
)
8181

82-
const Post = ({ post, postId }) => {
82+
function Post({ post, postId }) {
8383
useFirebaseConnect(`posts/${postId}`) // sync /posts/postId from firebase into redux
8484
return (
8585
<div>
@@ -90,3 +90,28 @@ const Post = ({ post, postId }) => {
9090

9191
export default enhance(Post)
9292
```
93+
94+
_Data that depends on props, an array as a query_
95+
96+
```javascript
97+
import { compose } from 'redux'
98+
import { connect } from 'react-redux'
99+
import { firebaseUseConnect, getVal } from 'react-redux-firebase'
100+
101+
const enhance = compose(
102+
connect((state, props) => ({
103+
post: getVal(state.firebase.data, `posts/${props.postId}`),
104+
}))
105+
)
106+
107+
function Post({ post, postId }) {
108+
useFirebaseConnect([`posts/${postId}`], [postId]) // sync /posts/postId from firebase into redux
109+
return (
110+
<div>
111+
{JSON.stringify(post, null, 2)}
112+
</div>
113+
)
114+
}
115+
116+
export default enhance(Post)
117+
```

docs/api/useFirestore.md

+7-37
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,10 @@
22

33
### Table of Contents
44

5-
- [createUseFirestore](#createusefirestore)
65
- [useFirestore](#usefirestore)
76

8-
## createUseFirestore
9-
10-
Function that creates a hook that which provides
11-
`firestore` object.
12-
13-
**WARNING!!** This is an advanced feature, and should only be used when
14-
needing to access a firebase instance created under a different store key.
15-
16-
**Parameters**
17-
18-
- `storeKey` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Name of redux store which contains
19-
Firestore state (`state.firestore`) (optional, default `'store'`)
20-
21-
**Examples**
22-
23-
_Basic_
24-
25-
```javascript
26-
import { createUseFirestore } from 'react-redux-firebase'
27-
28-
// create useFirestore that uses another redux store
29-
const useFirestore = createUseFirestore()
30-
31-
// use the useFirestore to wrap a component
32-
export default useFirestore(SomeComponent)
33-
```
34-
35-
Returns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Higher Order Component which accepts an array of
36-
watchers config and wraps a React Component
37-
387
## useFirestore
398

40-
**Extends React.Component**
41-
429
React hook that return firestore object.
4310
Firestore instance is gathered from `store.firestore`, which is attached
4411
to store by the store enhancer (`reduxFirestore`) during setup of
@@ -54,12 +21,15 @@ import { useFirestore } from 'react-redux-firebase'
5421

5522
function AddData({ firebase: { add } }) {
5623
const firestore = useFirestore()
57-
const add = todo => {
58-
firestore.collection('todos').add(todo)
24+
25+
function addTodo() {
26+
const exampleTodo = { done: false, text: 'Sample' }
27+
return firestore.collection('todos').add(exampleTodo)
5928
}
29+
6030
return (
6131
<div>
62-
<button onClick={() => add({ done: false, text: 'Sample' })}>
32+
<button onClick={addTodo}>
6333
Add Sample Todo
6434
</button>
6535
</div>
@@ -69,4 +39,4 @@ function AddData({ firebase: { add } }) {
6939
export default AddTodo
7040
```
7141

72-
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Firestore instance
42+
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Extended Firestore instance

docs/api/useFirestoreConnect.md

+12-16
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ React hook that automatically listens/unListens to provided
1111
firestore paths.
1212
**WARNING!!** This is an advanced feature, and should only be used when
1313
needing to access a firebase instance created under a different store key.
14-
Firestore state (state.firestore)
14+
Firebase state (state.firestore)
1515

1616
**Examples**
1717

1818
_Basic_
1919

2020
```javascript
21-
// props.firestore set on App component as firebase object with helpers
21+
// props.firestore set on App component as firestore object with helpers
2222
import { createUseFirestoreConnect } from 'react-redux-firebase'
2323

2424
const firestoreConnect = createUseFirestoreConnect()
@@ -34,12 +34,12 @@ React hook that automatically listens/unListens
3434
to provided Cloud Firestore paths. Make sure you have required/imported
3535
Cloud Firestore, including it's reducer, before attempting to use.
3636
**Note** Populate is not yet supported.
37-
**Note2** Only single path is allowed per one hook
3837

3938
**Parameters**
4039

41-
- `queriesConfig` **([Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) \| [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String))** An object or string for paths to sync
42-
from firestore. Can also be a function that returns the object or string.
40+
- `queriesConfig` **([Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) \| [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array) \| [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function))** An object, string,
41+
or array of object or string for paths to sync from firestore. Can also be
42+
a function that returns the object, string, or array of object or string.
4343

4444
**Examples**
4545

@@ -49,10 +49,10 @@ _Basic_
4949
import React from 'react'
5050
import { map } from 'lodash'
5151
import { connect } from 'react-redux'
52-
import { useFirestoreConnect } from 'react-redux-firebase'
52+
import { useFirebaseConnect } from 'react-redux-firebase'
5353

5454
function TodosList({ todosList }) {
55-
useFirestoreConnect('todos') // sync todos collection from Firestore into redux
55+
useFirebaseConnect('todos') // sync todos collection from Firestore into redux
5656

5757
return <ul>{_.map(todosList, todo => <li>{todo}</li>)}</ul>
5858
}
@@ -71,17 +71,13 @@ _Object as query_
7171
import React, { useMemo } from 'react'
7272
import { get } from 'lodash'
7373
import { connect } from 'react-redux'
74-
import { useFirestoreConnect } from 'react-redux-firebase'
74+
import { useFirebaseConnect } from 'react-redux-firebase'
7575

7676
function TodoItem({ todoId, todoData }) {
77-
const query = useMemo( // Make sure that everytime component rerender will not create a new query object which cause unnecessary set/unset listener
78-
() => ({
79-
collection: 'todos',
80-
doc: todoId
81-
}),
82-
[todoId] // useMemo's dependency
83-
)
84-
useFirestoreConnect(query) // sync todos collection from Firestore into redux
77+
useFirebaseConnect(() => ({
78+
collection: 'todos',
79+
doc: todoId
80+
}), [todoId]) // include dependency in the hook
8581

8682
return <div>{JSON.stringify(todoData)}</div>
8783
}

docs/api/withFirebase.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function AddTodo({ firebase: { push } }) {
6363
Add Sample Todo
6464
</button>
6565
</div>
66-
)
66+
)
6767
}
6868

6969
export default withFirebase(AddTodo)

docs/auth.md

+8
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ class SomeComponent extends Component {
4949
export default firebaseConnect()(SomeComponent) // or withFirebase(SomeComponent)
5050
```
5151

52+
#### Custom Claims
53+
54+
Firebase has a secure way of identifying and making claims about users with [custom claims](https://firebase.google.com/docs/auth/admin/custom-claims). This is a good way to provide roles for users.
55+
56+
If `enableClaims` config option is used along with `userProfile` you will find custom claims in `state.firebase.profile.token.claims`.
57+
58+
**Note**: If a claim is added to a user who is already logged in those changes will not necessarily be propagated to the client. In order to assure the change is observed, use a `refreshToken` property in your `userProfile` collection and update it's value after the custom claim has been added. Because `react-redux-firebase` watches for profile changes, the custom claim will be fetched along with the `refreshToken` update.
59+
5260
For examples of how to use this API, checkout the [auth recipes section](/docs/recipes/auth.html).
5361

5462
## login(credentials)

docs/getting_started.md

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const fbConfig = {}
4545
const rrfConfig = {
4646
userProfile: 'users',
4747
// useFirestoreForProfile: true // Firestore for Profile instead of Realtime DB
48+
// enableClaims: true // Get custom claims along with the profile
4849
}
4950

5051
// Initialize firebase instance

examples/complete/material/.env.local

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
NODE_PATH=src/
21
CI=false
32
# Needed to skip warnings from jest@beta in package.json
43
SKIP_PREFLIGHT_CHECK=true
+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
**/coverage/**
22
**/node_modules/**
33
dist/**
4+
build/**
45
src/index.html
56
blueprints/**
67
src/config.js

examples/complete/material/.eslintrc.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
module.exports = {
2-
'extends': ['react-app', 'prettier'],
2+
'extends': ['react-app', 'prettier', 'prettier/react'],
33
root: true,
44
parser: 'babel-eslint',
55
plugins: ['import', 'babel', 'react', 'prettier'],
66
settings: {
77
react: {
8-
version: '16.6'
8+
version: '16.8'
99
},
1010
'import/resolver': {
1111
node: {

examples/complete/material/.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
**/node_modules
99

1010
# React App
11-
**/build
11+
build
1212
src/config.js
1313
.env

examples/complete/material/firebase.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
"ignore": [
1111
"firebase.json",
1212
"**/.*",
13-
"**/node_modules/**"
13+
"**/node_modules/**",
14+
"jsconfig.json",
15+
"cypress/**"
1416
],
1517
"rewrites": [
1618
{

examples/complete/material/jsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"baseUrl": "./src",
44
"paths": {
55
"utils/*": [
6-
"utils/*",
6+
"utils/*"
77
]
88
}
99
},

0 commit comments

Comments
 (0)