Questions tagged [react-props]

ReactJS is a JS library developed by facebook. Props are the variables to be used in react components. Use tag when having doubts regarding usage of react props.

Reactjs is a JS library developed by facebook. React relies on making of components which handle variables through props.

Conceptually, components are like JavaScript functions. They accept arbitrary inputs (called “props”) and return React elements describing what should appear on the screen.

-React Documentation

3283 questions
9
votes
2 answers

How to call multiple setProps in enzyme?

I have the following test: import React from 'react'; import { configure, shallow } from 'enzyme' import Adapter from 'enzyme-adapter-react-16'; configure({ adapter: new Adapter() }); import ListAdapter from './ListAdapter' import TweetCard from…
Maverick
  • 2,738
  • 24
  • 91
  • 157
8
votes
4 answers

passing function from server to client component Next 13

According to the Next.js docs for the app directory: "Whenever possible, we recommend fetching data inside Server Components. Server Components always fetch data on the server." This is great because I am hitting an external API (where I cannot…
user20512643
8
votes
8 answers

ReactJS Props Undefined

I am learning how to use props. After taking research in either my mother language or english, I couldn't end up with a proper answer for my issue. Please tell me why this threw errors. This is the App.js file (default) import React from…
Thanh Vinh
  • 95
  • 1
  • 5
8
votes
2 answers

Can you use props on React.Fragment?

I know that a React Fragment can be used to group child components like this: render() { return ( ); } But can you add props to it? Say you want to use the…
Paul Razvan Berg
  • 16,949
  • 9
  • 76
  • 114
8
votes
1 answer

Pass down a function with same name in React

I can passdown props with spread operator. ie, is equal to: And we can use it in the component definition with the same name. My question is how can I pass a function like this? What…
Asim K T
  • 16,864
  • 10
  • 77
  • 99
7
votes
1 answer

React useContext not passing value down to deeply nested children

I'm brand new to the useContext hook and trying to figure out what I'm doing wrong... without the top imports, here's what my code looks like: So the root of my project looks like this: export default function App() { return (
7
votes
1 answer

React.cloneElement vs render props pattern

I'm learning React and trying to figure out the best way to dynamically add props. I know two approaches how to do that, but cannot understand which one is better and faster. First way is to use React.cloneElement api const Parent = ({ children })…
ValeryStatinov
  • 160
  • 1
  • 9
7
votes
3 answers

why react props are passed undefined to the child component?

I have get some data from db , when I console log them it works nice. and also when I stringfy the passed props are OK and displayed on the screen as they are expected. import axios from 'axios' import { URL } from '../../../../config' import…
Amir Meyari
  • 573
  • 4
  • 9
  • 30
7
votes
3 answers

render react component when prop changes

how to force render our component when props changes? how to force render parent component when child component's props changes? i searched a lot but all solutions are deprecated in new React version. in my any pages (Route exact path="/post/:id"…
7
votes
2 answers

Ant Design form set values form props

I'm using antd design in my form. Here I'm setting value from reducer profilereducer by using shouldComponentUpdate method. class ProfileForm extends Component { componentDidMount = () => { this.props.actions.getprofile() } …
Selvin
  • 795
  • 6
  • 12
  • 22
7
votes
5 answers

Props updated, componentDidUpdate did not fire

Is there ever a situation where componentDidUpdate would NOT fire, even if the props updated in React?
J Seabolt
  • 2,576
  • 5
  • 25
  • 57
7
votes
1 answer

How to properly handle subscriptions depending on property

I have a global service widgetService which holds data for a number of widgets, each identified by a widgetID. Each widget's data can change at any time. I want to display a widget with a React component, say WidgetReactComponent. The react…
Felk
  • 7,720
  • 2
  • 35
  • 65
7
votes
2 answers

React app componentDidMount not getting props from parent

I'm trying to pass props from a parent component to a child component and even though its getting called twice (dunno why, componentDidMount should get called only once) the props seem to be empty. Parent component: class Members extends Component{ …
Dieguinho
  • 758
  • 2
  • 14
  • 31
6
votes
1 answer

React.PureComponent and childs

Someone please explain me this last paragraph of the React documentation with a simple example, it's about React.PureComponent , all the examples I've seen are advanced and I'm just starting to know this concept and I can't see exactly what it…
user18944870
6
votes
0 answers

TypeScript & React: What's the difference between 'React.HTMLProps' and 'JSX.IntrinsicElements["T"]'

I am looking for the most "canonical" and/or "up-to-date" way to add a set of default HTML attributes as a set of allowed TypeScript props to a customized, "enhanced" HTML component, let's say a Button. I found two type definitions. The first is…
HynekS
  • 2,738
  • 1
  • 19
  • 34