我正在创建我的第一个React应用,我需要添加一个特定文档,其ID与我的Firestore集合中的用户ID相似,并且处于我的应用状态。我正在使用redux-firestore。有什么方法可以将状态的变量(user_id)传递给firestoreConnect属性
我刚刚开始使用React。所以我什至不知道从哪里开始
AnimatedBuilder(
animation: _animeController,
builder: (context, child) => Transform(
transform: Matrix4.translationValues(_anime.value * width * x, _anime.value * height * y, 0.0),
child: child,
),
child: Center(
child: CircleAvatar(
radius: 15.0,
backgroundColor: Colors.green,
),
),
);
关于如何将每个用户的用户ID传递到firestoreConnect的“ doc”属性并从用户集合中获取特定文档的任何想法。该用户标识以我的应用程序状态存在。
答案 0 :(得分:1)
您可以在组件内部使用useFirestoreConnect
,如下所示:
import { useFirestoreConnect } from 'react-redux-firebase';
class BuyDataContent extends Component {
constructor(props);
super(props);
const { USERID } = props; // get user id coming from mapStateToProps
useFirestoreConnect([
{
collection: 'users',
doc: USERID ,
storeAs: 'user', // indicate the response to be stored in a "user" property inside props
},
]);
const { user } = props; // get firestore response from "user" property
if (isEmpty(user)) {
... // check if the user is not loaded from firestore yet
}
// perform actions when user is loaded
...
还要从firestoreConnect
中删除compose
。
这应该可行,请查阅文档以供参考:https://react-redux-firebase.com/docs/api/useFirestoreConnect.html#examples