質問するログイン新規登録

質問編集履歴

7

2020/08/27 13:10

投稿

ug_o
ug_o

スコア39

title CHANGED
File without changes
body CHANGED
@@ -1,5 +1,6 @@
1
1
  ### 実現したいこと
2
2
  Firestoreから単一Documentを取得したいのですが、うまくいきません。
3
+ userDocがundefinedになります。
3
4
  記述方法が間違っているのでしょうか。
4
5
  よろしくお願いいたします。
5
6
 

6

タイトルの変更

2020/08/27 13:10

投稿

ug_o
ug_o

スコア39

title CHANGED
@@ -1,1 +1,1 @@
1
- Firestoreからデータを取得
1
+ Firestoreから単一Documentを取得したい
body CHANGED
@@ -1,5 +1,5 @@
1
1
  ### 実現したいこと
2
- Firestoreからデータを取得したいのですが、うまくいきません。
2
+ Firestoreから単一Documentを取得したいのですが、うまくいきません。
3
3
  記述方法が間違っているのでしょうか。
4
4
  よろしくお願いいたします。
5
5
 

5

ソースの修正

2020/08/27 02:04

投稿

ug_o
ug_o

スコア39

title CHANGED
File without changes
body CHANGED
@@ -5,27 +5,13 @@
5
5
 
6
6
  ## 該当のソースコード
7
7
  ```JS
8
- export class Edit extends React.Component {
9
- constructor(props) {
10
- super(props);
11
- this.inputRef = React.createRef();
12
- this.state = {
13
- name: "",
14
- profileImageUrl: "",
15
- };
16
- }
17
-
18
- async componentDidMount() {
8
+ async componentDidMount() {
19
- // Firestoreからユーザ情報を取得
9
+ // TODO: Firestoreからユーザ情報を取得
20
10
  try {
21
11
  const db = firebase.firestore();
22
12
  const user = getCurrentUser();
23
- const querySnapshot = await db.collection("users").doc(user.uid).get()
13
+ const userDoc = await db.collection("users").doc(user.uid).get();
24
-
25
- const userDoc = "";
26
- querySnapshot.forEach(doc => {
27
- userDoc.push(doc.data());
14
+ console.log(userDoc.data());
28
- });
29
15
  this.setState({
30
16
  name: userDoc.data.name,
31
17
  profileImageUrl: userDoc.data.image,

4

タグの追加

2020/08/27 01:58

投稿

ug_o
ug_o

スコア39

title CHANGED
File without changes
body CHANGED
File without changes

3

書式の改善

2020/08/26 07:05

投稿

ug_o
ug_o

スコア39

title CHANGED
File without changes
body CHANGED
@@ -1,14 +1,16 @@
1
1
  ### 実現したいこと
2
2
  Firestoreからデータを取得したいのですが、うまくいきません。
3
+ 記述方法が間違っているのでしょうか。
4
+ よろしくお願いいたします。
3
5
 
4
6
  ## 該当のソースコード
5
7
  ```JS
6
- export class EditSocial extends React.Component {
8
+ export class Edit extends React.Component {
7
9
  constructor(props) {
8
10
  super(props);
9
11
  this.inputRef = React.createRef();
10
12
  this.state = {
11
-     name: "",
13
+ name: "",
12
14
  profileImageUrl: "",
13
15
  };
14
16
  }
@@ -16,9 +18,14 @@
16
18
  async componentDidMount() {
17
19
  // Firestoreからユーザ情報を取得
18
20
  try {
21
+ const db = firebase.firestore();
19
22
  const user = getCurrentUser();
20
- const userDoc = await db.collection("users").doc(user.uid).get();
23
+ const querySnapshot = await db.collection("users").doc(user.uid).get()
24
+
21
- console.log(userDoc);
25
+ const userDoc = "";
26
+ querySnapshot.forEach(doc => {
27
+ userDoc.push(doc.data());
28
+ });
22
29
  this.setState({
23
30
  name: userDoc.data.name,
24
31
  profileImageUrl: userDoc.data.image,

2

文法の修正

2020/08/26 07:03

投稿

ug_o
ug_o

スコア39

title CHANGED
File without changes
body CHANGED
@@ -26,4 +26,5 @@
26
26
  } catch (error) {
27
27
  console.error(error);
28
28
  }
29
- }
29
+ }
30
+ ```

1

文法の修正

2020/08/24 08:45

投稿

ug_o
ug_o

スコア39

title CHANGED
@@ -1,1 +1,1 @@
1
- Firestoreのコレクションから特定のフィルドを取得して、描画させたい。
1
+ Firestoreからを取得
body CHANGED
@@ -1,13 +1,6 @@
1
1
  ### 実現したいこと
2
- FirebaseAuthでログイン中のドキュメント(uid)を取得してusersコレクションフィールドの値を取得し、<Input>タグに描画させたいです。
3
- 今回はnameフィルドを取得して下記の箇所に描画できるようにしたいのですが、うまくいきません。
2
+ Firestoreからデを取得したいのですが、うまくいきません。
4
- ```ここに言語を入力
5
- <Input
6
- value={this.state.name}
7
- />
8
3
 
9
- ```
10
-
11
4
  ## 該当のソースコード
12
5
  ```JS
13
6
  export class EditSocial extends React.Component {
@@ -15,58 +8,22 @@
15
8
  super(props);
16
9
  this.inputRef = React.createRef();
17
10
  this.state = {
11
+     name: "",
18
12
  profileImageUrl: "",
19
13
  };
20
14
  }
21
15
 
22
16
  async componentDidMount() {
23
- // TODO: Firestoreからユーザ情報を取得
17
+ // Firestoreからユーザ情報を取得
24
18
  try {
25
19
  const user = getCurrentUser();
26
20
  const userDoc = await db.collection("users").doc(user.uid).get();
27
21
  console.log(userDoc);
28
22
  this.setState({
29
23
  name: userDoc.data.name,
30
- about: userDoc.data.about,
31
24
  profileImageUrl: userDoc.data.image,
32
25
  });
33
26
  } catch (error) {
34
27
  console.error(error);
35
28
  }
36
- }
29
+ }
37
- ////省略////
38
- render() {
39
- return (
40
- <BaseLayout>
41
- <Column sidenav>
42
- <EditNav/>
43
- <div>
44
- <HeroText small="プロフィール">
45
- </HeroText>
46
- <Container>
47
- <FormItem label="アイコン">
48
- <UploadIcon/>
49
- </FormItem>
50
- <FormItem label="ユーザー名">
51
- <Input
52
- value={this.state.name}
53
- />
54
- </FormItem>
55
- <FormItem label="自己紹介">
56
- <TextArea/>
57
- </FormItem>
58
- <FormItem>
59
- <Button>
60
- 設定を保存
61
- </Button>
62
- </FormItem>
63
- </Container>
64
- </div>
65
- </Column>
66
- </BaseLayout>
67
- );
68
- }
69
- }
70
-
71
- export default withAuth(EditSocial);
72
- ```