I'm new to React and TypeScript.
I want to make a simple function that just fires a console.log(); I've gone through a few tutorials but don't really understand.
I've created an interface as such as per the tutorial:
interface ClickHandlerProps {
onClick; (event: React.SyntheticEvent<Event>, buttonType: string) => void
}
And in the return function I have:
<Button
onClick={(e) => props.onClick(e, "button1")}
>
But the tutorial kind of ends there. I don't really know how to just fire a console.log().
I know it's a bit vague, but could anyone help me out and point me in the right direction?
Full code:
import React from 'react';
import { Button, Grid } from '@material-ui/core';
interface ClickHandlerProps {
onClick; (event: React.SyntheticEvent<Event>, buttonType: string) => void
}
const ActionButtons = ({ onClick }: EventHandlerProps) => {
return (
<>
<Grid container spacing={3}>
<Grid item xs={4}>
<Button onClick={(e) => props.onClick(e, "button1")} >
Button 1
</Button>
</Grid>
<Grid item xs={4}>
<Button onClick={(e) => props.onClick(e, "button2")} >
Button 2
</Button>
</Grid>
</Grid>
</>
);
};
export default ActionButtons;
On index.tsx
import ActionButtons from './ActionButtons';
export default ActionButtons;