This doesn't display an image, but still works as a button.
<button><img src={"./img/google.png"} /></button>
My folder setup is /user/img/google.png and /user/loginGoogle.jsx , so I don't think there is a problem with source
This doesn't display an image, but still works as a button.
<button><img src={"./img/google.png"} /></button>
My folder setup is /user/img/google.png and /user/loginGoogle.jsx , so I don't think there is a problem with source
This will work:
<button><img src="./img/google.png" alt="my image" onClick={this.myfunction} /></button>
then if you define:
myfunction() {
console.log("CLICKED");
}
and if you click your image you will see CLICKED appearing in the console.
So if you add the onClick listener to your image it will work. Then you can wrap that image in a button and even add some CSS class to it to match your needs.
If you're using React bootstrap button, typescript code work as below.
import { Button } from 'react-bootstrap'
<Button style={{backgroundImage:"url('./images/logo.png')",backgroundSize:"cover", width:"40px", height:"40px"}}></Button>
You can use an 'img' as a button, it has an onClick property. It will also be easier to set hover effects and to do general styling that way.
<img src={<url>} alt=<alt-string> width=<width> height=<height> onClick={() => <onClick function>}/>
<img src={require('/images/myImage.png')} />
make sure to change the file directory and name to your specific file.
import logo from './logo.png'; // Tell webpack this JS file uses this image
// Import result is the URL of your image return ;