New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-use-dock

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-use-dock

A hook to render dynamic content into a Dock

latest
Source
npmnpm
Version
1.1.1
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

React Use Dock

A hook to render dynamic content into a Dock!

Visit Demo

demo

Install

(requires React version ^16.8.0)

# npm
npm i react-use-dock

# Yarn
yarn add react-use-dock

Usage

Wrap application with DockProvider

import { DockProvider } from 'react-use-dock'

function MyApp() {
  return (
    <DockProvider>
      <Layout>
        <AppContent />
      </Layout>
    </DockProvider>
  )
}

Add Dock component into your component tree

import { Dock } from 'react-use-dock'

function Layout({ children }) {
  return (
    <div>
      <header>
        <h1>React Use Dock</h1>
      </header>

      <main>{children}</main>

      <footer>Stuff</footer>

      {/* Dock is absolutely positioned, place anywhere */}
      <Dock />
    </div>
  )
}

Use Dock

import { useEffect } from 'react'
import { useDock, DockContainer } from 'react-use-dock'

function Example() {
  const dock = useDock()

  // provide any render function!
  const render = () => (
    <DockContainer onCloseDock={() => console.log('Closed dock')}>
      <YourDockContent />
    </DockContainer>
  )

  useEffect(() => {
    dock.openDock({
      render,
      minSize: 350,
      orientation: 'right',
      size: 50,
    })
  }, [])

  return (
    <div>
      <button onClick={dock.toggleDock}>Toggle Dock</button>
    </div>
  )
}

API

useDock hook

View the useDock() api in the Docs

Dock

The Dock component is where the render function is called to display content.

interface DockProps {
  id?: string
  style?: React.CSSProperties
}
NameDescriptionDefault
idid attribute for the Docks <div>. Useful for css selectionreact-use-dock
styleInline styles{}

DockContainer

The DockContainer component is a simple wrapper component that renders a close icon at the top right.

interface DockContainerProps {
  children: any
  onCloseDock?(): void
  CloseIcon?: ReactNode
}
NameDescriptionDefault
childrenReact child components-
onCloseDockCallback when dock is closed() => {}
CloseIconCustom React component for close icon<span style={{ fontSize: '1.5em' }}>&times;</span>
import { DockContainer } from 'react-use-dock'

function Example() {
  return (
    <DockContainer
      onCloseDock={() => console.log('Closed Dock')}
      CloseIcon={<span>Close Dock</span>}
    >
      <YourDockContent />
    </DockContainer>
  )
}

Keywords

react

FAQs

Package last updated on 04 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts