react-props

TypeScript: Interface cannot simultaneously extends two types

拥有回忆 提交于 2021-02-18 22:31:24
问题 I'm writing a React app using TypeScript. I use material-ui for my components. I'm writing a custom wrapper for material-ui's Button component. It looks like this: import MUIButton, { ButtonProps } from "@material-ui/core/Button"; import withStyles, { WithStyles } from "@material-ui/core/styles/withStyles"; import classNames from "classnames"; import React, { PureComponent } from "react"; import styles from "./styles"; export interface OwnProps { color: "primary" | "danger" | "warning" |

Passing useState as props in typescript

杀马特。学长 韩版系。学妹 提交于 2021-02-15 11:44:18
问题 Say I have a parent component with two child components: const Parent = () => { const [myVar, setmyVar] = useState(false) return ( <> <MyChildComponent1 myVar={myVar} setMyVar={setMyVar} \> <MyChildComponent2 myVar={myVar} \> </> ) } Now how would I go about setting the type correctly in MyChildComponent2 ? This is what I've come up with so far: const MyChildComponent1 = ( {myVar, setMyVar}: {myVar: boolean, setMyVar: (value: boolean) => void}) = (...) Is the type for setMyvar correct? Or

Re-render same component on url change in react

半城伤御伤魂 提交于 2021-02-04 18:48:12
问题 I have a route which takes an id and renders the same component for every id, for example : <Route path='/:code' component={Card}/> Now the in the Link tag I pass in an id to the component.Now the Card component fetches additional detail based on the id passed. But the problem is it renders only for one id and is not updating if I click back and goto the next id. I searched and found out that componentsWillReceiveProps can be used but during recent versions of React it has been deprecated. So

TypeError: Cannot read property 'map' of undefined, Is passing an array as a prop to a functional component not possible?

筅森魡賤 提交于 2021-01-29 22:11:08
问题 I am following a MERN stack tutorial in which a parent component Dashboard passes an array of objects from its own props (after mapStateToProps) to another component Education. Trying to iterate through this array in Education component gives me the above mentioned error. Please help, the tutorial seemed to have no errors and I have followed it perfectly so why the issue? <Education education={profile.education}/> (passing the prop in Dashboard.js) education is an array of objects inside an

React Native “Undefined is not an object (evaluating 'this.props')”

删除回忆录丶 提交于 2021-01-29 15:00:53
问题 I am new to react native. I have created location access file. and now I want to Navigate to "Welcome " Screen. But getting error like this "Undefined is not an object (evaluating 'this.props')" here is my code of location access file import React, { useState, useEffect } from 'react'; import { Platform, Text, View, StyleSheet } from 'react-native'; import * as Location from 'expo-location'; export default function App() { const [location, setLocation] = useState(null); const [errorMsg,

React Button Click Hiding and Showing Components

走远了吗. 提交于 2021-01-29 09:47:07
问题 I have a toggle button that show and hides text. When the button is clicked I want it to hide another component and if clicked again it shows it. I have created a repl here: https://repl.it/repls/DapperExtrasmallOpposites I want to keep the original show / hide text but I also want to hide an additional component when the button is clicked. How to I pass that state or how do I create an if statement / ternary operator to test if it is in show or hide state. All makes sense in the repl above!

Passing props to child components with a React Navigation

风流意气都作罢 提交于 2021-01-29 05:35:13
问题 I'm trying to figure out how to pass props to the 'Camera' component but getting a syntax error when i try component= { Camera doSomething={this.doSomething}} cant seem to find documentation to help on this one. Im sure its simple if you know how - hoping someone can assist. my code import React, { Component } from 'react'; import Camera from './camera' import VideoComponent from './video' import AudioComponent from './audio' import File from './file' import { createMaterialBottomTabNavigator

Passing input state from parent to child component

风流意气都作罢 提交于 2021-01-28 20:11:41
问题 I want to pass the value and setValue to Right component . I've done something but it's not working.I am typing but it's deleting immediately.I can't see even what I am typing to textinput.What is the proper way to do this ? export const Vault = ({ navigation }: VaultStackNavigationProps<"Vault">) => { const [value, setValue] = useState(""); React.useLayoutEffect(() => { navigation.setOptions({ headerRight: () => ( <Right setText={setValue} value={value} /> ), }); }, [navigation]); return ( /

Passing UseState from child component to parent component?

﹥>﹥吖頭↗ 提交于 2021-01-27 20:28:52
问题 I am trying to pass up the state "region" defined in my useState Hook to the parent element. Im not sure where to put the word region in order to do that though? This is the Child Element import React from 'react'; export default function SimpleMenu() { const [region, setRegion] = useState("Africa"); const filterRegion = (e) => { setRegion(e.target.value); }; return ( <div> <Button aria-controls="simple-menu" aria-haspopup="true" onClick={handleClick}> Filter by Region </Button> <Menu>

How to pass async state to child component props?

被刻印的时光 ゝ 提交于 2021-01-22 18:30:31
问题 I'm new to react and I am trying to fetch data from an API and pass the data to a child component. I've passed the data to the state on my parent component, however, when I pass it to the child component as props it logs as an empty array. I'm sure there is something simple I am overlooking but I don't know what, my code is below PARENT COMPONENT import React, {Component} from 'react'; import Child from '../src/child'; import './App.css'; class App extends Component { constructor(props) {