score:1
are you sure about returning two adjacent MyComponent over there? And I think that you miss the curly braces when getting the props in the son component definition =
({ selectedOption, onClick, customSectionStyle })
score:0
const Son: React.FC<{ selectedOption?: string | '', onClick?: (href: string, section: string) => void | void, customSectionStyle?: string | '' }> = (selectedOption, onClick, customSectionStyle)
Replace with
const Son: React.FC<{ selectedOption?: string, onClick?: (href: string, section: string) => void, customSectionStyle?: string }> = ({ selectedOption, onClick, customSectionStyle })
score:0
Son Will be called with all props that you've to Destructur it or directly read from props
(selectedOption, onClick, customSectionStyle) should be ({selectedOption, onClick, customSectionStyle})
const Son: React.FC<{ selectedOption?: string | '', onClick?: (href: string, section: string) => void | void, customSectionStyle?: string | '' }> = ({selectedOption, onClick, customSectionStyle}) => {
return(
<MyComponent onClick={() => {onClick('/','home')}} customStyle={selectedOption === 'rooms' ? customSectionStyle : ''}/>
<MyComponent onClick={() => {onClick('/','settings')}} customStyle={selectedOption === 'settings' ? customSectionStyle : ''}/>
//...
)
}
Source: stackoverflow.com
Related Query
- How to pass a function with parameters in react with typescript
- How to pass parameters in react functions with Typescript
- How do I pass a function with parameters to child element in react and immediately invoke it?
- React prop types with TypeScript - how to have a function type?
- How to specify function parameters for React component callback with TypeScript?
- How to use jest.spyOn with React function component using Typescript
- How can ı pass function with state for react useContext
- How to pass additional props throughout a Route element that has parameters in a Typescript based React Web Application
- How to test with jest and typescript with types a basic react function component
- How to pass arguments to callback in React + Typescript without new function creation?
- How to pass parameters in React Function From 1 file to another
- How to handle typescript function overloading with React Props
- How do I pass props and other parameters to function using React Hooks?
- How to pass Unicode characters as function parameters in React
- How to pass function with React Hooks?
- Pass down function with multiple parameters to child component w/ TypeScript
- How to create React Context that passes a function with Typescript
- How to pass a function with arguments as prop in React without creating an arrow function
- How to create a generic arrow function with react and typescript
- How to pass function as many prop in react typescript (useState([]), useState(boolean))
- React js, pass a function with parameters as props without using this keyword
- How to implement a generic arrow function as interface property in Typescript with React JSX
- How to pass function as a prop in react typescript
- React Typescript how to pass props with types
- how can i pass a useState hook defined with typescript down to another react component?
- How can I pass a function when linking with React Router?
- How to pass a parameter to a filter method & calling the function in React onClick event with different params?
- How to pass parameter from child to parent using function in react with es6 syntax
- How to pass Parameters with require tag in React
- How to inject parameters into return function with custom hook react
More Query from same tag
- how to add background color only for actived item in a <li> using styled component?
- Why React hook useState don't increment index onClick?
- Make part of the text as link.(react - localization)
- Using epoch as time series on x axis in react-chartjs-2 not showing correct date
- How to pass multiple GTM tags in gatsby-plugin-google-tagmanager plugin?
- react-bootstrap-tabs library, compliation error
- i have imported everything but still it throws this error TypeError: can't access property "url", postDetails is undefined
- Gatsby use custom javascript
- React.js submit button didn't work on Console Log?
- React : Navigation between Components (Component-Instances)
- Node JS : JSON Refactoring based on the city
- Semantic.ui dropdown not working with React.js
- React - Multiple components with the same actions & reducers
- Log minified JavaScript errors in production code
- How to solve Unexpected token error in project with ReactJs and frontend-maven-plugin?
- React: Prop value inside event callback not updated
- How to get value from <li> tag
- List Cognito Users in React web app
- How to update data for react table
- Griddle v1 onRowClick not firing
- How to properly change setState in my situation
- define generic redux action creator in typescript
- Set field value with formik to react-select component from external button
- React-Tabs and React-Selection: Tabs Steal Focus From Select
- Reduce array of objects to render additional rows in a table
- React - How can I access a particular position in the array, and then change it?
- Where do I find the object names of icons in the FontAwesome free packages?
- Formik with two "master-slave" selects
- helper function overwriting previous values in mapped list in react
- How to mock react custom hook return value as a module with Jest