Browse Source

Add brief about using Context

master
Dejvino 11 months ago
parent
commit
f6eadb0df7
6 changed files with 43 additions and 2 deletions
  1. BIN
      public/photo.png
  2. +4
    -0
      src/Person.ts
  3. +15
    -0
      src/app/components/AboutBrief.tsx
  4. +14
    -0
      src/app/components/PersonContext.tsx
  5. +7
    -2
      src/app/layout.tsx
  6. +3
    -0
      src/app/page.tsx

BIN
public/photo.png View File

Before After
Width: 290  |  Height: 290  |  Size: 14 KiB

+ 4
- 0
src/Person.ts View File

@@ -0,0 +1,4 @@
export const Person = {
name: "David Hrdina Němeček",
brief: "Software developer, people manager."
};

+ 15
- 0
src/app/components/AboutBrief.tsx View File

@@ -0,0 +1,15 @@
import React, { useContext } from 'react';
import Container from 'react-bootstrap/Container';
import Image from 'react-bootstrap/Image'
import { PersonContext } from './PersonContext';

export default function AboutBrief() {
const person = useContext(PersonContext)
return (
<Container className='about-brief'>
<Image alt='Photograph of the person' rounded={true} src='photo.png'></Image>
<h1>{person.name}</h1>
<p className='brief'>{person.brief}</p>
</Container>
)
}

+ 14
- 0
src/app/components/PersonContext.tsx View File

@@ -0,0 +1,14 @@
'use client'
import React from 'react';
import { createContext } from 'react';
import { Person } from '../../Person';

export const PersonContext = createContext(Person);

export function PersonProvider({ children }) {
return (
<PersonContext.Provider value={Person}>
{children}
</PersonContext.Provider>
)
}

+ 7
- 2
src/app/layout.tsx View File

@@ -2,11 +2,12 @@ import React from 'react'
import { Inter } from 'next/font/google'

import './globals.css'
import { PersonProvider } from './components/PersonContext'

const inter = Inter({ subsets: ['latin'] })

export const metadata = {
title: 'David Hrdina Němeček | CV',
title: 'David Hrdina Němeček | CV.',
description: 'Curriculum Vitae',
}

@@ -17,7 +18,11 @@ export default function RootLayout({
}) {
return (
<html lang="en">
<body className={inter.className}>{children}</body>
<body className={inter.className}>
<PersonProvider>
{children}
</PersonProvider>
</body>
</html>
)
}

+ 3
- 0
src/app/page.tsx View File

@@ -2,10 +2,13 @@
import React from 'react';
import Container from 'react-bootstrap/Container';
import JobsHistory from './components/JobsHistory';
import AboutBrief from './components/AboutBrief';

export default function Home() {
return (

<Container fluid='xxl'>
<AboutBrief></AboutBrief>
<JobsHistory></JobsHistory>
</Container>
)


Loading…
Cancel
Save