I have two Buttons in my component. the 'submit note' button refreshes the page (submits the form?) though the function handler for it only says to console.log. The "add note" button does not refresh the page. Both buttons are a part of the form, and both have arrow functions attached to them. Why isn't the "add note" function also refreshing the page? Is it because any component that changes state cannot also submit?
const Button = ({handleClick, text}) => {
return (
<button onClick={handleClick}>{text}</button>
)
}
export default Button; //component in separate file. added here for clarity
const NoteContainer = () => {
const [click, setClick] = useState(false)
const handleClick = () => setClick(true)
const submitNote = () => console.log('note submitted')
if (click === true) {
return (
<div>
<Note />
<Button handleClick={submitNote} text="Submit Note" />
</div>
)
}
return (
<div>
<Button handleClick={handleClick} text='Add Note'/>
</div>
)
}
export default NoteContainer;