Reputation: 161
I am using React Typescript.
import React from "react";
function PostButton(props){
let style = {
width:24,
height:24,
src: "../images/abc.png"
};
return(
<button style={style} onClick={() => props.handleClick()}>{props.label}</button>
);
}
return (
<div style={style}>
<PostButton src={"../images/abc.png"} handleClick = {props.incrementScore}/>
</div>
);
}
Upvotes: 1
Views: 6429
Reputation: 2441
Damian's answer is technically correct however if you're using webpack you'll need to import the image like this:
import abc from "../images/abc.png";
And use it like this:
function PostButton(props){
let style = {
width:24,
height:24,
background: `url(${abc})`,
};
return(
<button style={style} onClick={() => props.handleClick()}>{props.label}</button>
);
}
Upvotes: 1
Reputation: 7495
src
would be background:url(../images/abc.png)
Perhaps you're confusing the src
prop that an img
HTML element would have?
Perhaps you should include a nested img
component inside your button.
Working example: https://stackblitz.com/edit/react-emotion-hello-u9qyaa
Upvotes: 1