Skip to content

Commit 820b191

Browse files
committed
states, events and props
1 parent 9c82dee commit 820b191

File tree

14 files changed

+121
-125
lines changed

14 files changed

+121
-125
lines changed

src/App.css

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/App.test.tsx

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/App.tsx

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/events/EventComponent.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react";
2+
3+
const EventComponent: React.FC = () => {
4+
const onChange = (event: React.ChangeEvent<HTMLInputElement>): void => {
5+
console.log(event);
6+
};
7+
const onDragStart = (event: React.DragEvent<HTMLDivElement>) => {
8+
console.log(event.screenY);
9+
};
10+
return (
11+
<div>
12+
<input onChange={onChange} />
13+
<div draggable onDragStart={onDragStart}>
14+
Drag Me
15+
</div>
16+
</div>
17+
);
18+
};
19+
20+
export default EventComponent;

src/index.css

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/index.tsx

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
1-
import React from 'react';
2-
import ReactDOM from 'react-dom/client';
3-
import './index.css';
4-
import App from './App';
5-
import reportWebVitals from './reportWebVitals';
1+
import ReactDom from "react-dom";
2+
import EventComponent from "./events/EventComponent";
63

7-
const root = ReactDOM.createRoot(
8-
document.getElementById('root') as HTMLElement
9-
);
10-
root.render(
11-
<React.StrictMode>
12-
<App />
13-
</React.StrictMode>
14-
);
4+
const App = () => {
5+
return (
6+
<div>
7+
<EventComponent />
8+
</div>
9+
);
10+
};
1511

16-
// If you want to start measuring performance in your app, pass a function
17-
// to log results (for example: reportWebVitals(console.log))
18-
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
19-
reportWebVitals();
12+
ReactDom.render(<App />, document.querySelector("#root"));

src/logo.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/props/Child.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
interface ChildProps {
2+
color: string;
3+
onClick: () => void;
4+
children?: React.ReactNode;
5+
}
6+
7+
export const Child = ({ color, onClick }: ChildProps) => {
8+
return (
9+
<div>
10+
{color} <button onClick={onClick}>Click Me</button>
11+
</div>
12+
);
13+
};
14+
15+
export const ChildAsFC: React.FC<ChildProps> = ({
16+
color,
17+
onClick,
18+
children,
19+
}) => {
20+
return (
21+
<div>
22+
{color}
23+
{children}
24+
{color} <button onClick={onClick}>Click Me</button>
25+
</div>
26+
);
27+
};

src/props/Parent.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { ChildAsFC } from "./Child";
2+
3+
const Parent = () => {
4+
return (
5+
<ChildAsFC color="red" onClick={() => console.log("clicked")}>
6+
sfds
7+
</ChildAsFC>
8+
);
9+
};
10+
export default Parent;

src/react-app-env.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
/// <reference types="react-scripts" />

0 commit comments

Comments
 (0)