我正在尝试将用户输入数据保存到firebase的实时数据库中。 我没有使用身份验证。 我只需要在实时数据库的firebase数据字段中获取我的用户输入数据。 我现在有一个空数据库。
但是当我点击提交按钮将数据推送到firebase时,我收到以下错误
我的行动:
import firebase from 'firebase'; import { TRIVIA_POST } from
> './types';
>
>
> export const triviaPost = ({ anss }) => {
>
> return (dispatch) => {
> firebase.database().ref(`/answers`)
> .push({ anss })
> .then(() => {
> dispatch({ type: TRIVIA_POST });
> }); }; };
我的减速机:
import {
TRIVIA_POST
} from '../actions/types';
const INITIAL_STATE = {};
export default (state = INITIAL_STATE, action) => {
switch (action.type) {
case TRIVIA_POST:
return action.payload;
default:
return state;
}
};
Reducer Index.js
import { combineReducers } from 'redux';
import SceoneReducer from './SceoneReducer';
export default combineReducers({
triviaPost: TriviaReducer
});
我的答案提交屏幕:
import React, { Component } from 'react'; import { View, Image, Span }
> from 'react-native'; import { Container, Header, Title,
> Content, Button, Footer, FooterTab, Text, Body, Left,
> Right, Icon } from 'native-base'; import axios from 'axios'; import
> Card from './Card'; import CardSection from './CardSection'; import
> Input from './Input'; import { connect } from 'react-redux'; import {
> triviaPost } from './actions';
>
>
> class Trivia extends Component { state = { trivia: [], time:[] };
>
> componentWillMount() {
> axios.get("firebase_link")
> .then(response => this.setState({trivia: response.data}));
> }
> onButtonPress() {
> const { anss } = this.props;
>
> this.props.triviaPost({ anss });
> } render() {
> return (
> <Container>
> <Header>
> <Left>
> <Button transparent onPress={() => this.props.navigation.navigate('DrawerOpen')}>
> <Icon name="arrow-back" />
> </Button>
> </Left>
> <Body>
> <Title>Trivia Time</Title>
> </Body>
> <Right />
> </Header>
> <Card> <CardSection>
> <Image style={{ height: 200, width: null, flex: 1 }} source = {{ uri: this.state.trivia.tq }} /> </CardSection>
> </Card>
> <View style={{width: null, height: 50, backgroundColor: 'white'}} />
> <Card> <CardSection>
> <Text style={{ fontSize: 16, flex: 1 }}>The Upcoming Trivia Time is @ {this.state.trivia.time} IST</Text> </CardSection>
> </Card>
> <View style={{width: null, height: 50, backgroundColor: 'white'}} />
> <Card>
> <CardSection>
> <Input
> label="Answer"
> placeholder="Enter Answer"
> value={this.props.anss}
> />
> </CardSection>
> <View style={{width: null, height: 50, backgroundColor: 'white'}} />
> <Footer>
> <Button onPress={this.onButtonPress.bind(this)}>
> <Text>Submit Answer</Text>
> </Button>
> </Footer>
> </Card>
> </Container>
> ); } }
>
> export default connect(null, { triviaPost })(Trivia);
请帮助我 提前致谢