react-props

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

本小妞迷上赌 提交于 2019-12-01 20:51:14
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 the save button, will be added directly on the calendar and it will be appeared on the calendar. My

Pass props to another component onclick of a button

≡放荡痞女 提交于 2019-12-01 11:35:57
In my nextJS app, I want to pass props of one component to another which is neither a parent nor child of first component.How can I do that? There is a Order component inside a div in Orders page and OrderViewer in another div.What I want is that when I click the 'View Order' button, orderno of that order should pass to OrderViewer component. orders.js <div> <div><Order orderno='abc' title='abc' status='abc' entity='abc' po='abc' duedate='abc' /></div> </div> <div><OrderViewer /></div> Order.js <div> <button>View Order</button> <p><span>{this.props.orderno}</span> <span>{this.props.title}<

How to use generics in props in React in a functional component?

不问归期 提交于 2019-11-30 05:17:22
问题 In a class based component, I can easily write some code like this: import * as React from 'react'; import { render } from 'react-dom'; interface IProps<T> { collapsed: boolean; listOfData: T[]; displayData: (data: T, index: number) => React.ReactNode; } class CollapsableDataList<T> extends React.Component<IProps<T>> { render () { if (!this.props.collapsed) { return <span>total: {this.props.listOfData.length}</span> } else { return ( <> { this.props.listOfData.map(this.props.displayData) } </

PropTypes in functional stateless component

被刻印的时光 ゝ 提交于 2019-11-28 21:49:28
问题 Without using class, how do I use PropTypes in functional stateless component of react? export const Header = (props) => ( <div>hi</div> ) 回答1: The official docs show how to do this with ES6 component classes, but the same applies for stateless functional components. Firstly, npm install / yarn add the new prop-types package if you haven't already. Then, add your propTypes (and defaultProps too if required) after the stateless functional component has been defined, before you export it.