@abdulghani/breakpointcontext 中文文档教程

发布于 4年前 浏览 26 项目主页 更新于 3年前

Breakpointcontext

一个用于断点的 react.js 挂钩,它提供了上下文以进行有效检查

Install

从 yarn/npm 中获取它,无论

yarn add @abdulghani/breakpointcontext

npm install @abdulghani/breakpointcontext

Usage

使用它多么简单,只要

import BreakpointContext, { useBreakpoint } from "@abdulghani/breakpointcontext";

const MyComponent = () => {
  return (
    <BreakpointContext>
      <YourSuperAwesomeChildren>
    </BreakpointContext>
  )
}

// and use it in your component
const YourSuperAwesomeChildren = () => {
  const breakpoint = useBreakpoint();

  if (breakpoint === "sm")
    return <div>it's small</div>
  else
    return <div>it's huge</div>
}

您可以放置​​自己的配置来定义您自己的断点集,

const MyComponent = () => {
  return (
     <BreakpointContext breakpoints={myBreakpoints}>
      <YourSuperAwesomeChildren>
    </BreakpointContext>
  )
}

选项就是这样输入的

type breakpoints = {
  [keys: string]: number; // set of breakpoint value tied to the key as the label
};

Breakpointcontext

a react.js hook for breakpoint that's provided with context for efficient checking

Install

get it from yarn/npm whatever

yarn add @abdulghani/breakpointcontext

npm install @abdulghani/breakpointcontext

Usage

use it as simple as

import BreakpointContext, { useBreakpoint } from "@abdulghani/breakpointcontext";

const MyComponent = () => {
  return (
    <BreakpointContext>
      <YourSuperAwesomeChildren>
    </BreakpointContext>
  )
}

// and use it in your component
const YourSuperAwesomeChildren = () => {
  const breakpoint = useBreakpoint();

  if (breakpoint === "sm")
    return <div>it's small</div>
  else
    return <div>it's huge</div>
}

you can put your own config to define your own set of breakpoints

const MyComponent = () => {
  return (
     <BreakpointContext breakpoints={myBreakpoints}>
      <YourSuperAwesomeChildren>
    </BreakpointContext>
  )
}

the option is typed as such

type breakpoints = {
  [keys: string]: number; // set of breakpoint value tied to the key as the label
};
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文