react hooks props in useEffect

If the value of props.filters did not change, then React would skip the effect. // This will only re-run if the value of `props.filters` changes useEffect(() => { fetchSomeData(props.filters); }, [props.filters]); With hooks, React does this internally unlike the implementation using componentDidUpdate where we have to compare the value of prevProps and nextProps against each … Read more

Specify specific props and accept general HTML props in Typescript React App

We can have a look at how div props are defined: interface IntrinsicElements { div: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>; } If we use React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> as the base type we will have all properties of div. Since DetailedHTMLProps just adds ref to React.HTMLAttributes<HTMLDivElement> we can use just this as the base interface to get all div properties: … Read more

How to pass props to Screen component with a tab navigator?

you can use the property ‘children’ to pass an element type jsx like instead of the property ‘component’, is recomended from react-native. On this way you can pass props to component example: <tab.Screen name=”home” children={()=><ComponentName propName={propValue}/>} /> is neccesary to use ‘()=>’ because the property children need a function that return a jsx element, it’s … Read more

React propTypes component class?

For anyone using PropTypes >= 15.7.0 a new PropTypes.elementType was added in this pull request and was released on february 10, 2019. This prop type supports all components (native components, stateless components, stateful components, forward refs React.forwardRef, context providers/consumers). And it throws a warning when is not any of those elements, it also throws a … Read more

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

According to the principle of least privilege, this is a correct way: <InnerComponent name={object.name} image={object.image} /> This restricts InnerComponent from accidentally modifying original object or accessing properties that aren’t intended for it. Alternatively, properties could be picked from original object and passed as props: <InnerComponent {…pick(object, ‘name’, ‘image’)} /> If there are numerous properties that … Read more

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

You can’t create a functional component with a type annotation and make it generic. So this will NOT work as T is not defined and you can’t define it on the variable level: const CollapsableDataList : React.FunctionComponent<IProps<T>> = p => { /*…*/ } You can however skip the type annotation, and make the function generic … Read more

PropTypes in functional stateless component

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 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. import … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)