React Native中有奇怪的功能吗?

时间:2018-11-07 09:53:31

标签: reactjs react-native

import React, { Component } from 'react';
import axios from 'axios';
import { View } from 'react-native';
import { Text } from 'native-base';
import { IP_ADDRESS } from '../../authentication/local';

class QuestionerDetail extends Component {
    constructor(props) {
        super(props);
        this.state = {
            userData: '',
        }

        this.getUser = this.getUser.bind(this);
    }

    componentDidMount() {
        console.log("*********************************");
        const questionerId = this.props.questionerId;
        console.log("questionerId: ", questionerId);
        this.getUser(questionerId);
    }

    getUser(questionerId) {
        console.log("questioner details: ", questionerId);
        axios.get(`http://${IP_ADDRESS}/api/userDatas/${questionerId}`)
            .then(response => {
                this.setState({ userData: response.data });
            })
            .catch(err => {
                console.log("WHAT THE FUCK ERR: "+err);
            });
    }

    render() {
        const { userData, questionerId } = this.state;

        return(
            <View style={{ marginBottom: 20, display: 'flex', flexDirection: 'row', justifyContent: 'flex-end' }}>

            </View>
        )
    }
}
export default QuestionerDetail;

我只是在React Native中看到怪异的功能,服务器日志记录getUser被两次调用,且未定义且实际为questionId,这怎么可能?

这是服务器输出

  

请求GET / api / userDatas / undefined的未处理错误:错误:   未知的“ userDatas” ID“未定义”。       在Function.convertNullToNotFoundError(C:\ Users \ User \ Desktop \ Courses \ React \ UnvHub \ node_modules \ loopback \ lib \ persisted-model.js:91:17)       在invokeRestAfter(C:\ Users \ User \ Desktop \ Courses \ React \ UnvHub \ node_modules \ strong-remoting \ lib \ rest-adapter.js:531:25)       在C:\ Users \ User \ Desktop \ Courses \ React \ UnvHub \ node_modules \ async \ dist \ async.js:3880:24       补充时(C:\ Users \ User \ Desktop \ Courses \ React \ UnvHub \ node_modules \ async \ dist \ async.js:1011:17)       在iterateeCallback(C:\ Users \ User \ Desktop \ Courses \ React \ UnvHub \ node_modules \ async \ dist \ async.js:995:17)       在C:\ Users \ User \ Desktop \ Courses \ React \ UnvHub \ node_modules \ async \ dist \ async.js:969:16       在C:\ Users \ User \ Desktop \ Courses \ React \ UnvHub \ node_modules \ async \ dist \ async.js:3885:13       在interceptInvocationErrors(C:\ Users \ User \ Desktop \ Courses \ React \ UnvHub \ node_modules \ strong-remoting \ lib \ remote-objects.js:724:22)       在C:\ Users \ User \ Desktop \ Courses \ React \ UnvHub \ node_modules \ async \ dist \ async.js:473:16       补充时(C:\ Users \ User \ Desktop \ Courses \ React \ UnvHub \ node_modules \ async \ dist \ async.js:1006:25)       在iterateeCallback(C:\ Users \ User \ Desktop \ Courses \ React \ UnvHub \ node_modules \ async \ dist \ async.js:995:17)       在C:\ Users \ User \ Desktop \ Courses \ React \ UnvHub \ node_modules \ async \ dist \ async.js:969:16       在C:\ Users \ User \ Desktop \ Courses \ React \ UnvHub \ node_modules \ async \ dist \ async.js:473:16       补充时(C:\ Users \ User \ Desktop \ Courses \ React \ UnvHub \ node_modules \ async \ dist \ async.js:1006:25)       在iterateeCallback(C:\ Users \ User \ Desktop \ Courses \ React \ UnvHub \ node_modules \ async \ dist \ async.js:995:17)       在C:\ Users \ User \ Desktop \ Courses \ React \ UnvHub \ node_modules \ async \ dist \ async.js:969:16

{ title: 'Dependency inversion principle - Wikipedia',


body:
   'In object-oriented design, the dependency inversion principle refers to a specific form of .... The presence of interfaces to accomplish the Dependency Inversion Pattern (DIP) have other design implications in an object-oriented program:.\n',
  tags: List [ 'ajax', 'xml', 'java' ],
  date: '2018-10-28T16:12:34+03:00',
  questionerId: '5bd5b4f514567662f4de4d64',
  answers: List [ '5bd5b5f414567662f4de4d67' ],
  voteNumber: 0,
  numberOfViews: 15,
  shortComments:
   List [ '5bdef447a028f42228e3a2ca', '5be093a30bd2f637a44827d4' ],
  usersUpVoted: List [],
  usersDownVoted: List [],
  id: 5bd5b5c314567662f4de4d66 }

0 个答案:

没有答案