Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
289 views
in Technique[技术] by (71.8m points)

javascript - React: How to pass a function ("interpolations") to a styled component's template

I'm trying to build a bar graph using react. I'm using props to try to pass a function ("interpolations") to a styled component's template in styled component but its showing an error message:

my styled-component:

export const Bar = styled.div`
  border-radius: 3px;
  height: 55px;
  background-color: #64b2d1;
  width: ${props => props.width};
  animation-name: ${showBarOne};
  animation-duration: 1.2s;
  animation-delay: 0.1s;
  animation-fill-mode: forwards;
`;

my component:

const Volume = ({widthBar}) =>{

  return(
     <VolumeContainer>
       
        <ProgressContainer>
          <Bar width='{widthBar}' ></Bar>
        </ProgressContainer>
     </VolumeContainer>
   )
  }

its showing a error inside the Volume component on the width variable.

No overload matches this call. Overload 1 of 2, '(props: Pick<Pick<Pick<DetailedHTMLProps<HTMLAttributes, HTMLDivElement>, "slot" | "style" | ... 252 more ... | "onTransitionEndCapture"> & { ...; }, "slot" | ... 254 more ... | "onTransitionEndCapture"> & Partial<...>, "slot" | ... 254 more ... | "onTransitionEndCapture"> & { ...; } & { ...; }): ReactElement<...>', gave the following error. Type '{ width: string; }' is not assignable to type 'IntrinsicAttributes & Pick<Pick<Pick<DetailedHTMLProps<HTMLAttributes, HTMLDivElement>, "slot" | ... 253 more ... | "onTransitionEndCapture"> & { ...; }, "slot" | ... 254 more ... | "onTransitionEndCapture"> & Partial<...>, "slot" | ... 254 more ... | "onTransitionEndCapture"> & { ...; } & { ...; }'.

question from:https://stackoverflow.com/questions/65893178/react-how-to-pass-a-function-interpolations-to-a-styled-components-templat

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...