npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-props-manager

v1.2.0

Published

Manage your props in a single space

Downloads

3

Readme

react-props-manager

Manage your props in a single space

NPM JavaScript Style Guide

This library intends to be an easy way to control props in components that are often used, or can have multiple props. Getting your props inside your component can keep you code cleaner and easier to read. This pattern is based on a Redux model, but simpler to use and props focused.

Install

npm install --save react-props-manager

Usage

Create the props constant

It must be an object and each node key on root level is a collection of props that will be acessible by a component. The props can be any value or type and can have as many properties as we want.

const propsValue = {
  home: {
    title: 'Home Page',
    subtitle: 'Subtitle of home page',
    backgroundColor: '#339989'
  },
  about: {
    title: 'About Us',
    subtitle: 'Subtitle of about us',
    backgroundColor: '#1F487E'
  },
  docs: {
    title: 'Docs',
    subtitle: 'Subtitle of docs',
    backgroundColor: '#FB3640'
  }
}

Wrap your app with the Provider

On the root of your project, wrap your app content with the provider and pass your props to it.

import React from 'react'
import { PropsManagerProvider } from 'react-props-manager'

const App = () => {
  return (
    <div style={{ flex: 1, width: '100%', height: '100%' }}>
      <PropsManagerProvider propsValue={propsValue}>
        <HeaderMenu />
        <Switch>
          <Route path='/home' component={Home} />
          <Route path='/about' component={AboutUs} />
          <Route path='/docs' component={Docs} />
        </Switch>
      </PropsManagerProvider>
    </div>
  )
}

Get your props in any component passing the key value

Use the hook usePropsContext to retrieve getProps function, with getProps we can recover our props object, and if needed as in the exemple bellow, we can type the returned object, case the id passed didn't match any props it will return an empty object.

import React from 'react'
import { usePropsContext } from 'react-props-manager'

type ManagedProps = {
  title: string
  description: string
  backgroundColor: string
}

const Container: React.FC<ContainerProps> = ({ children, id }) => {
  const { getProps } = usePropsContext()
  const { backgroundColor, description, title } = getProps(id) as ManagedProps

  return (
    <div style={{ ...styles.container, backgroundColor: backgroundColor }}>
      <div style={styles.contentContainer}>
        <h1>{title}</h1>
        <p>{description}</p>
        {children}
      </div>
    </div>
  )
}

Contributions

In order to contribute with this project, fork the repo, create a new branch and fill all relevant information about your PR in the PR description. Feel free to address any possible bug or improvement and send us a pull request.

License

MIT © BenHurMartins