Frontend разработчик. Библиотека электронных книг и статей для frontend разработчиков.
React.ComponentProps.
import { ComponentProps } from "react";
import { ExternalComponent } from "external-lib";
type InternalComponentProps = ComponentProps<typeof ExternalComponent> & {
outerClassName: string;
};
- React.MouseEventHandler. Используется для типизации колбека события мыши.
import { MouseEventHandler, } from "react";
type ComponentProps = {
caption: string;
onClick: MouseEventHandler<HTMLButtonElement>;
};
const Component = (props: ComponentProps) => (
<div>
<button onClick={props.onClick}>{props.caption}</button>
</div>
);
- Pick. Используется для создания нового типа объекта, принимает два аргумента: исходный тип объекта и список ключей для выбора из исходного объекта. В React можно использовать для создания интерфейса пропсов, когда какой-то интерфейс расшарен между несколькими.
type ComponentProps = Pick<Something, "propA" | "propB" | "children"> & {
wrapperClassName?: string;
}
export const Component = (props: ComponentProps) => (
…
);
www.chakshunyu.com/blog/7-…velopers
✍️ @React_lib<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JavaScript Math object's PI property</title>
</head>
<body>
<script>
// Printing PI value
document.write(Math.PI + "<br>"); // Prints: 3.141592653589793
// Function to calculate circle area
function calculateCircleArea(radius){
var area = (Math.PI) * radius * radius;
return area;
}
document.write(calculateCircleArea(3) + "<br>"); // Prints: 28.274333882308138
document.write(calculateCircleArea(8) + "<br>"); // Prints: 201.06192982974676
</script>
</body>
</html>
Выход
3.141592653589793
28.274333882308138
201.06192982974676
Объект Math — это встроенный объект JavaScript, поэтому к его свойствам и методам можно обращаться напрямую. Вам никогда не понадобится создавать объект Math, потому что он автоматически создается интерпретатором JavaScript.
👉 @frontend_1