I have a problem with React and Typescript and it will be nice if I get some help from you guys!
I'm trying to assign an onclick event to my child box component but it isn't working, it doesn't trigger any error, just plainly doesn't work.
This his is the parent:
changeActive = (issue: boolean) => {
console.log(issue);
this.setState({ color: true });
}
render() {
return (
<div>
<div className="box">
<h4 onClick={() => this.changeActive(true)}>Choose your finish.</h4>
<div className="box--vertical">
<Item htitle="Ivory White" onClick={() => this.changeActive} active={ this.state.color ? 'active' : ' ' } text="For the past 75 years, Sennheiser has put sound first. The new MOMENTUM True." price=" " />
<Item htitle="Matte Black" onClick={() => this.changeActive} active={ this.state.color ? ' ' : 'active' } text="Of all of the celestial bodies that capture our attention and fascination as astronomers." price=" " />
</div>
</div> )};
And this is the child element:
import * as React from "react";
interface Props { active: string, htitle: string, text: string, price: string, onClick: (event: React.MouseEvent<HTMLDivElement>) => void };
export function Item(Props: Props) {
return (
<div className={`item ${Props.active}`} onClick={Props.onClick}>
<div>
<span>{Props.htitle}</span>
{Props.text !== " " ? <p>{Props.text}</p>: ""}
</div>
{Props.price !== " " ? <span>+${Props.price}</span>: "" }
</div>
);
}
export default Item;
I'm certainly at loss here, as I'm new to react and typescript and I will like there is no error on this he execution.