In this episode of Syntax, Scott and Wes talk about using React with Typescript — how to set it up, components, state, props, passing data, custom hooks, and more!
Get a 30 day free trial of Freshbooks at freshbooks.com/syntax and put SYNTAX in the “How did you hear about us?” section.
If you want to know what’s happening with your code, track errors and monitor performance with Sentry. Sentry’s Application Monitoring platform helps developers see performance issues, fix errors faster, and optimize their code health. Cut your time on error resolution from hours to minutes. It works with any language and integrates with dozens of other services. Syntax listeners new to Sentry can get two months for free by visiting Sentry.io and using the coupon code TASTYTREAT during sign up.
Whether you’re working on a personal project or managing enterprise infrastructure, you deserve simple, affordable, and accessible cloud computing solutions that allow you to take your project to the next level. Simplify your cloud infrastructure with Linode’s Linux virtual machines and develop, deploy, and scale your modern applications faster and easier. Get started on Linode today with a $100 in free credit for listeners of Syntax. You can find all the details at linode.com/syntax. Linode has 11 global data centers and provides 24/7/365 human support with no tiers or hand-offs regardless of your plan size. In addition to shared and dedicated compute instances, you can use your $100 in credit on S3-compatible object storage, Managed Kubernetes, and more. Visit linode.com/syntax and click on the “Create Free Account” button to get started.
04:55 - Components
type Props = { value: string; } const App = (props: Props) => <div />
It means that all components accept children, even if they're not supposed to
12:13 - Props
const defaultJoke: JokeProps = { joke: 'LOL JOE', id: 'YEAH', status: 200, }; function JokeItem({ joke = defaultJoke }: JokeProps): JSX.Element { return ( {joke.joke} = {joke.id} ); }
18:38 - State
const [user, setUser] = useState(null);
22:27 - useEffect
useEffect(() => { console.log('Mounted'); // getJoke().then(console.log).catch(console.error); void getJoke(); }, [getJoke]);
26:09 - Refs
const ref1 = useRef(null!);
29:33 - Custom Hooks
31:00 - Context
const AppCtx = React.createContext(null);
35:21 - Events
onClick={e ⇒ yeah(e.target)}
const onSetType = (e: React.ChangeEvent) => setType(e.target.value)
39:27 - ForwardRef
type Props = { children: React.ReactNode; type: "submit" | "button" }; export type Ref = HTMLButtonElement; export const FancyButton = React.forwardRef((props, ref) => ( ));
41:30 - ESLint
46:20 - React as Global React 17
import * as react from "react" import * as react_dom from "react-dom" declare global { type React = typeof react type ReactDOM = typeof react_dom }
48:08 - TSConfig
jsx: "react"
53:05 - Frameworks?
📆 2021-05-31 15:00 / ⌛ 00:25:54
📆 2021-05-26 15:00 / ⌛ 01:03:39
📆 2021-05-24 15:00 / ⌛ 00:28:48
📆 2021-05-19 15:00 / ⌛ 01:02:44
📆 2021-05-17 15:00 / ⌛ 00:21:31