This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Storybook | |
on: | |
push: | |
paths: ["stories/**", "src/**"] | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout 🛎️ | |
uses: actions/[email protected] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
useEffect(() => { | |
console.log(title) | |
}, [title]) // Re-run the effect only if title was changed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
useEffect(() => { | |
// to do smth... | |
return () => { | |
// to do smth else when a component is unmounted... | |
} | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//componentDidMount and componentDidUpdate. An effect re-runs every render | |
useEffect(() => { | |
// to do smth... | |
}) | |
//componentDidMount. An effect runs only on mount | |
useEffect(() => { | |
// to do smth... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Component = React.memo(function Component(props) { | |
// your code is here... | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { ReactElement, useState } from "react" | |
import TabTitle from "./TabTitle" | |
type Props = { | |
children: ReactElement[] | |
} | |
const Tabs: React.FC<Props> = ({ children }) => { | |
const [selectedTab, setSelectedTab] = useState(0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react" | |
type Props = { | |
title: string | |
index: number | |
setSelectedTab: (index: number) => void | |
} | |
const TabTitle: React.FC<Props> = ({ title, setSelectedTab, index }) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react" | |
import Tabs from "../Tabs" | |
import Tab from "../Tabs/Tab" | |
function App() { | |
return ( | |
<Tabs> | |
<Tab title="Lemon">Lemon is yellow</Tab> | |
<Tab title="Strawberry">Strawberry is red</Tab> | |
<Tab title="Pear">Pear is green</Tab> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react" | |
type Props = { | |
title: string | |
} | |
const TabTitle: React.FC<Props> = ({ title}) => { | |
return ( | |
<li> |