score:1
Accepted answer
when you are passing in icon={<icon2 />}
you are actually passing a jsx element, which cannot be styled from the other side with styled-components because it is not a component. to style a component, it needs to take the classname
as a prop. in this case, your best bet is to write a styled-component wrapper dev
and let the styles cascade to your {props.icon}
but because you are not passing in any props to icon
you could easily pass in the component as a prop making it stylable.
<basewidget icon={icon1} />
where you are receiving it:
import styled from "styled-components";
const styledicon = styled.i``;
const basewidget = (props) => {
const { icon } = props.icon;
return (
<styledicon as={icon} />
);
}
Source: stackoverflow.com
Related Query
- How to use Styled Components for a component passed as props
- How to use custom props and theme with material-ui styled components API (Typescript)?
- Styled Components - use styled component as base for another component
- How to pass styles via props with styled components without having to create the component inside the component
- How to reuse function type inside a component for other components props
- Props not being passed when using custom document for styled components
- How to use useRef() for multiple components and to scroll down to a specific component when user clicks
- How can a Styled Components Theme be passed as Props to a Material UI component?
- Can't use props for styled components with emotion-js and typescript
- Styled Components - How to style a component passed as a prop?
- Styled components - How do I create a style that inherits a component and is able to send props to the parent?
- How to implement an props interface for conditions with styled components in React with Typescript
- How can I use different properties for the same component using Styled Component for React JS?
- React - How to pass props to a component passed as prop
- How to extend styled component without passing props to underlying DOM element?
- How to use an array as option for react select component
- How to extend props for Material-UI components using Typescript?
- How to pass props to a styled component in emotion? Using TypeScript
- Multiple Props Options for Styled Components
- How to pass style props for a specific component in react-native
- How to use Media Queries inside a React Styled Components Keyframe?
- TypeScript: Extend React component props for styled component element
- How redux work when multiple components use parts of complex objects for it's source
- Enzyme, How to access a component passed in props
- React Typescript how send props and use it in child component
- How to define that component passed must have certain props but allow extra props too
- How do I test props passed to child component using Enzyme Shallow?
- How to serve a React component library dependent on Styled Components to another library that also has a Styled Comopnents dependency?
- How to use this.refs for a list of child components
- Strict CSP: How to set nonce for styled components in next.js?
More Query from same tag
- setState works but redux store update doesn't
- How can I prevent certain characters from being deleted from a React input tag?
- Bootstrap Flex and JavaScript
- How to dynamically request a React Component based on a variable value?
- Helmet causing MERN app hosted on heroku cause ERROR: Refused to execute inline script because it violates the following
- React passing value from dropdown back to parent component
- Pass props to child component in React, with Typescript (TSX file)
- Custom CSS in iFrame Widget (React, MUI)
- Add new user on button click in reactJS
- React.js check if user is logged in after redirect and display a popup
- How download package from unpkg or add in dependencies unpkg package?
- Getting error on running command `npm run build`, error `TypeError: MiniCssExtractPlugin is not a constructor`
- React 17.0.1: Invalid hook call. Hooks can only be called inside of the body of a function component
- Allow mjs extension files in React with typescript and craco
- What happens when using this.setState multiple times in React component?
- Fetch response db.json is one object instead an array of objects
- Chakra UI Modal component does not work with Array of object
- React REST request to Java backend failing
- ReactJS doesn't recognize a value in an object in an array
- Redux/React. TypeError: Cannot call a class as a function
- React state variable output as string but passes undefined as a prop
- Implement Load More button in Next JS
- Type text into a React input using javascript (Tampermonkey script)?
- Dynamic content inside Trans Component i18next
- React multiple children seem to be sharing the component handler function
- Donut chart labels on DevExtreme for React
- how to fix this Error Cannot use the same canvas during multiple render() operations
- How can I delete Multiple array items
- TypeError: Cannot read property 'first_name' of null
- How to debug JS of a dynamically loaded page?