Skip to content
Snippets Groups Projects
Verified Commit f44248b7 authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

feat: initial reactive example

parent b5bad528
No related branches found
No related tags found
1 merge request!8Support for react.js components
Pipeline #1057 passed
import React from "react";
import React, { useState } from "react";
import ReactDOM from "react-dom/client";
import { Button } from "./components";
......@@ -6,8 +6,10 @@ import { Button } from "./components";
import "./app.css";
export const App = () => {
const getText = () => "Hello World";
return <Button text={getText()} />;
const [count, setCount] = useState(0);
const getText = () => `Hello World ${count}`;
const onClick = () => setCount(count + 1);
return <Button text={getText()} onClick={onClick} />;
};
export const startApp = (element: string) => {
......
......@@ -2,20 +2,26 @@ import React, { FC } from "react";
import "./button.css";
export const Button: FC<{ text: string; size?: string; style?: string[] }> = ({
type ButtonProps = {
text: string;
size?: string;
style?: string[];
onClick?: () => void;
};
export const Button: FC<ButtonProps> = ({
text,
size = "small",
style = ["simple", "border"]
style = ["simple", "border"],
onClick = undefined
}) => {
const onClick = () => {
alert("Hello World");
};
const classes = () => ["button", size, ...style].join(" ");
const _onClick = () => (onClick ? onClick() : undefined);
return (
<span className={classes()} onClick={onClick}>
<span className={classes()} onClick={_onClick}>
{text}
</span>
);
};
export default Button;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment