react-props

React foreach in JSX

谁都会走 提交于 2019-12-17 18:24:58
问题 I have a object that I want to output via REACT question = { text: "Is this a good question?", answers: [ "Yes", "No", "I don't know" ] } and my react component (cut down), is another component class QuestionSet extends Component { render(){ <div className="container"> <h1>{this.props.question.text}</h1> {this.props.question.answers.forEach(answer => { console.log("Entered"); //This does ifre <Answer answer={answer} /> //THIS DOES NOT WORK })} } export default QuestionSet; as you can see from

Props updated, componentDidUpdate did not fire

不羁岁月 提交于 2019-12-13 15:30:27
问题 Is there ever a situation where componentDidUpdate would NOT fire, even if the props updated in React? 回答1: There are 3 conditions that can cause componentDidUpdate to not fire: 1) You wrote a custom shouldComponentUpdate that returned false. 2) The internal react methods determined that there was no change in the virtual DOM, so it chose not to re-render. 3) You extended something other than React.Component (such as PureComponent) which has a default shouldComponentUpdate method that

React - “Is not a function” error when passing function as props to functional component

耗尽温柔 提交于 2019-12-13 03:56:59
问题 I'm relatively new to React and I'm working on a ToDo list style Recipe app. I asked a previous question here about refactoring a functional component so that recipe ingredients would appear on separate lines instead of all appearing as one single line paragraph. I implemented the suggested changes and used a second .map function to iterate through ingredients and successfully got them to appear on separate lines. However, after implementing the changes now I get an error when the user clicks

React JS Storing an array of ids in state

寵の児 提交于 2019-12-12 10:21:52
问题 I have a prop called friends which is being listed as a checkboxes (default: unselected). Example output: o Bob Smith o Tom Brown How can I save the id's of all the names that are selected? E.g. both are ticked/selected -> ids 1 and 2 is stored. This is what I have so far: class SelectFriends extends Component { constructor(props) { super(props) this.state = { SelectedFriendsIds: [], } } render() { const { SelectedFriendsIds } = this.state const { userId, friends, addFriendsTo } = this.props

Navigation.getParam is undefined while trying to pass function as parameter

好久不见. 提交于 2019-12-11 23:46:06
问题 I'm trying to use a function from my Main component in my details component which I user react navigation to navigate to and I want to save some changes in detail screen in my main component //Main.js import React from 'react'; import { StyleSheet , Text, View, TextInput, ScrollView, TouchableOpacity, KeyboardAvoidingView, AsyncStorage } from 'react-native' import Note from './Note' import { createStackNavigator, createAppContainer } from "react-navigation"; import Details from './Details';

Update props from other component in react native

坚强是说给别人听的谎言 提交于 2019-12-11 15:18:44
问题 I have a Main class which I show an array to user, then in detail page user can edit each element which I'm passing using react navigation parameter. I want to edit my array in the detail class and save it using async storage. //Main.jsimport React from 'react'; import { StyleSheet , Text, View, TextInput, ScrollView, TouchableOpacity, KeyboardAvoidingView, AsyncStorage } from 'react-native' import Note from './Note' import detail from './Details' import { createStackNavigator,

Closing modal in child component React Native

泪湿孤枕 提交于 2019-12-11 14:46:27
问题 I have two components in react native and I'm unable to close a modal from my child component. ListTrips - Parent ModalAddTrip - Child ListTrips.js import ModalAddTrip from './ModalAddTrip'; .... .... this.state = { isModalAddTripVisible: false } .... handleDismissModalAddTrip = () => { this.setState({ isModalAddTripVisible: false }); }; closeModal() { this.refs.ModalAdd.handleDismissModalAddTrip(); } .... <ModalAddTrip ref="ModalAdd" isVisible={this.state.isModalAddTripVisible}

React - Using ternary to apply CSS class in functional component

橙三吉。 提交于 2019-12-11 14:33:35
问题 I'm relatively new to React and working on a John Conway - Game of Life app. I have built a Gameboard.js functional component for the board itself (which is a child of App.js ) and a Square.js functional component which represents an individual square in the board (and is a child of Gameboard and a grandchild of App ). In App I have a function called alive which I want to change the color of an individual square when it is clicked by the user. App also has an 'alive' property in it's state

REACT NATIVE - Change state of screen when close import modal

我是研究僧i 提交于 2019-12-11 03:35:39
问题 When I close the modal, I need to detect that it has been closed to change the state of the parent page. Not being able to change it when I change any property of the state, the modal. ExpertFeedback.js import ModalExpertFeedback from './ModalExpertFeedback'; export default class ExpertFeedback extends Component { constructor(props) { super(props); this.state = { modalVisible: false, projects: [{name:'project0', name:'project1'}], feedback: {title: '', content: '', project_id: ''} }; }

Access state of parent component in a child component?

被刻印的时光 ゝ 提交于 2019-12-08 13:52:45
问题 I'm new to react js and I need to get the state of the component to be accessed by another class, I encountered this problem because I'm using atomic design because writing everything in one component is turning to be a problem, here is my code: Headcomponent : class Headcomponent extends React.Component{ constructor (props) { super(props); this.state = { email: '', password: '', formErrors: {email: '', password: ''}, emailValid: false, passwordValid: false, formValid: false, items: [], } }