Skip to content

Commit 4dc0706

Browse files
authored
static props : 3 examples
1 parent a6e3c13 commit 4dc0706

File tree

12 files changed

+78
-99
lines changed

12 files changed

+78
-99
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: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
import React from 'react';
2-
import logo from './logo.svg';
3-
import './App.css';
4-
5-
function App() {
2+
import Hello from './components/Hello';
3+
import Name from './components/Name';
4+
import { CustomTyper } from './components/Childs/Child';
5+
import { Child1 } from './components/Childs/Child1';
6+
const App =() => {
67
return (
7-
<div className="App">
8-
<header className="App-header">
9-
<img src={logo} className="App-logo" alt="logo" />
10-
<p>
11-
Edit <code>src/App.tsx</code> and save to reload.
12-
</p>
13-
<a
14-
className="App-link"
15-
href="https://reactjs.org"
16-
target="_blank"
17-
rel="noopener noreferrer"
18-
>
19-
Learn React
20-
</a>
21-
</header>
22-
</div>
8+
<>
9+
<h1>Hello TS</h1>
10+
<Hello name='Bharat' age={21} gender="Male" />
11+
<Name name={{first: 'Bharat', last: 'Kumar'}} />
12+
<CustomTyper>This text goes to child component.</CustomTyper>
13+
<Child1>
14+
<CustomTyper>This is where we use a custom component in another component.</CustomTyper>
15+
</Child1>
16+
</>
2317
);
2418
}
2519

26-
export default App;
20+
export default App;

src/components/Childs/Child.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react'
2+
type ChildProps = {
3+
children: string
4+
}
5+
6+
export const CustomTyper = (props : ChildProps) => {
7+
return (
8+
<>
9+
<h2>{props.children}</h2>
10+
<p><i>above text came from parent : app.tsx</i></p>
11+
</>
12+
)
13+
}

src/components/Childs/Child1.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react'
2+
type NewProps = {
3+
children : React.ReactNode
4+
}
5+
export const Child1 = (props : NewProps) => {
6+
return (
7+
<>
8+
{props.children}
9+
</>
10+
)
11+
}

src/components/Home.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from 'react'
2+
type HelloProps = {
3+
name: string,
4+
age : number,
5+
gender ?: 'Male' | 'Female' //its optional prop
6+
}
7+
const Hello = (props: HelloProps) => {
8+
return (
9+
<>
10+
Hi {props.name}!
11+
<p>Is your age {props.age} ?</p>
12+
<button>yes</button>
13+
<h5>you are a : {props.gender}</h5>
14+
</>
15+
)
16+
}
17+
18+
export default Hello;

src/components/Name.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react'
2+
type NameProps = {
3+
name : {
4+
first: string,
5+
last: string
6+
}
7+
}
8+
const Name = (props : NameProps) => {
9+
return (
10+
<div>
11+
<p>First Name: {props.name.first}</p>
12+
<p>Last Name: {props.name.last}</p>
13+
</div>
14+
)
15+
}
16+
17+
export default Name;

src/index.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
body {
2-
margin: 0;
2+
margin: 0;padding: 0;
33
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
44
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
55
sans-serif;

src/index.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,12 @@ import React from 'react';
22
import ReactDOM from 'react-dom/client';
33
import './index.css';
44
import App from './App';
5-
import reportWebVitals from './reportWebVitals';
5+
66

77
const root = ReactDOM.createRoot(
88
document.getElementById('root') as HTMLElement
99
);
10+
1011
root.render(
11-
<React.StrictMode>
12-
<App />
13-
</React.StrictMode>
12+
<App />
1413
);
15-
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();

src/logo.svg

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

0 commit comments

Comments
 (0)