React Native не может найти переменную: стиль? - PullRequest
0 голосов
/ 11 февраля 2020
import React, { Component } from 'react';
import { Platform, StyleSheet, View, TextInput, Button } from 'react-native';

export default class App extends Component {

  state = {
    placeName: ""
  }

  PlaceNameChangerHandler = val => {
    this.setState({
      placeName: val
    });
  };

  render() {
    return (
      <View style={style.container}>
        <View style={styles.inputcontainer}>
          <TextInput
            placeholder="A awsome place"
            value={this.state.placeName}
            onChangeText={this.PlaceNameChangerHandler}
            style={style.placeinput}
          />
          <Button title="Addd" style={style.placebutton} />
        </View>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: "#fff",
    alignItems: "center",
    marginTop: 50,
    justifyContent: "flex-start",
  },
  inputcontainer: {
    flex: 1,
    width: "100%",
    flexDirection: "row",
    alignItems: "center",
    justifyContent: "space-between"
  },
  placeinput: {
    width: "70%"
  },
  placebutton: {
    width: "30%"
  }

});

Ответы [ 2 ]

0 голосов
/ 12 февраля 2020

Измените метод рендеринга на этот, и он должен работать, просто замените стиль на стили:

render() {
    return (
      <View style={styles.container}>
        <View style={styles.inputcontainer}>
          <TextInput
            placeholder="A awsome place"
            value={this.state.placeName}
            onChangeText={this.PlaceNameChangerHandler}
            style={styles.placeinput}
          />
          <Button title="Addd" style={styles.placebutton} />
        </View>
      </View>
    );
  }
0 голосов
/ 11 февраля 2020

Ваша таблица стилей называется styles

...