react-props

Access props inside quotes in React JSX

拜拜、爱过 提交于 2020-01-19 04:14:09
问题 In JSX, how do you reference a value from props from inside a quoted attribute value? For example: <img className="image" src="images/{this.props.image}" /> The resulting HTML output is: <img class="image" src="images/{this.props.image}"> 回答1: React (or JSX) doesn't support variable interpolation inside an attribute value, but you can put any JS expression inside curly braces as the entire attribute value, so this works: <img className="image" src={"images/" + this.props.image} /> 回答2: If you

React app componentDidMount rendering twice

邮差的信 提交于 2020-01-06 07:27:30
问题 I've got a simple react app that has a Login that receives a Json Web Token on successful authentication and the passes it to a sibling component (Members) that in its componentDidMount uses this JWT to make a fetch call to the server. The thing is that componentDidMount is being called twice, the first one with undefined JWT and the second time with the retrieved JWT. Heres my code: App (parent code): class App extends Component{ state = { clientToken: '' } callbackGetToken = (token) => {

React app componentDidMount rendering twice

余生颓废 提交于 2020-01-06 07:26:39
问题 I've got a simple react app that has a Login that receives a Json Web Token on successful authentication and the passes it to a sibling component (Members) that in its componentDidMount uses this JWT to make a fetch call to the server. The thing is that componentDidMount is being called twice, the first one with undefined JWT and the second time with the retrieved JWT. Heres my code: App (parent code): class App extends Component{ state = { clientToken: '' } callbackGetToken = (token) => {

React props: Should I pass the object or its properties? Does it make much difference?

被刻印的时光 ゝ 提交于 2020-01-03 07:04:08
问题 When passing props should I pass the entire object into the child components or should I individually create props first in the parent component and then pass those props to the child? Pass entire object: <InnerComponent object={object} /> Individually create props that're needed first: <InnerComponent name={object.name} image={object.image} /> Which one is preferred and if it depends, what should I use as a gauge to use either? 回答1: You should prefer your second example, to pass the props

can we pass a value when we move to next component using this.props.history.push(“/next Component”)?

a 夏天 提交于 2020-01-01 19:45:12
问题 I want to send Task_id to the ShowRecommendation.js component recommend = Task_id => { this.props.history.push("/ShowRecommendation"); }; How it can be done? 回答1: With react-router you can transfer "state" this.props.history.push({ pathname: '/ShowRecommendation', state: { taskid: Task_id } }) and at the ShowRecommendation.js componenet you can get the value using console.log(this.props.location.state) Comment if you have more questions 来源: https://stackoverflow.com/questions/59095211/can-we

How to passing data from component to another component on reactJs using map?

淺唱寂寞╮ 提交于 2019-12-24 23:55:42
问题 I have a react-big-calendar, I want when I click on new event, the dialog of the hour will be having the values of the hour clicked on the new event, for example, I click the mouse from 07:30 to 08:30, so I want to get this hour on my dialog as the value of the input of start and end state, but, I have the same dialog by clicking on the button "Ajouter disponibilité" which his position is above of the calendar, when I click it I will have the hour of the moment, and at both of them I can

passing props to componentDidMount

北城以北 提交于 2019-12-24 09:05:39
问题 Able to render props in my Dashboard component, unable to pass this to componentDidMount for further ajax processing. Render is working fine and display information. I am using firebase and that's working correctly. App.js // React core. import React, { Component } from 'react'; import Dashboard from './components/Dashboard'; class App extends Component { //firebase... state = { isSignedIn: undefined, displayName: undefined, email: undefined }; componentDidMount() { this.setState(

Pass function by props in react router

半世苍凉 提交于 2019-12-24 07:16:02
问题 I know how to pass props in the react router like string type for example. But I have a problem when I try to pass props of function. On my children component, this props is "undefined" . Exemple of my Link : <Link to={'/Content/' + this.props.index + '/' + this.props.decreaseIndexProject}>Page n°1</Link> The index props is a number, so I can get it on my children component, but not the decreaseIndexProject props. I use PropType : NavBar.propTypes = { indexProject: PropTypes.number,

Passing state from a child to parent component

狂风中的少年 提交于 2019-12-21 17:50:09
问题 Is there any proper way to access a property in the state of a child component and get its value from a parent component? I have a component called "itemSelection" where I map through an api response to get some items like this <div className="row"> {this.state.items.map(i => <Item ref="item" id={i.id} name={i.name} quantity={i.quantity} />)} </div> In the Item component there a property in the state called "selected" which I want to know its value if it was true or false in the itemSelection

How to send data from dialog back to parent container with react?

南楼画角 提交于 2019-12-19 23:20:10
问题 I have a react-big-calendar (The parent container), I have also a select which, the events of the calendar are fetched according to this select ( doctor name ) and I have a button when I click on it, the dialog will be appears (another component), on this dialog, I have a form to add an event after the select, when I post my API, I save it on local storage, but the event added doesn't appears on my calendar just after refresh the page and reselect the doctor name. But I want, when I click on