When you click and page reloads…

when you have a button on a page that, when you click, reloads the page and you don’t know why, it maybe that your button is within the form tag and defaults the type to submit. Make sure your button has a type specified as a button to solve that.

<Form>
{/* some code */}
  <MyButton>My Button</MyButton>
{/* some code */}
</Form>
import React from 'react';

const MyButton = () => <button type="button">{children}</button>
export default MyButton;
This entry was posted in HTML, JavaScript, ReactJS and tagged , , , , . Bookmark the permalink.