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

redux-title

v0.0.3

Published

Synchronization of document title and redux state

Downloads

176

Readme

redux-title

This library provides synchronization of the document title and redux state. This means when you update document.title you will see an updated redux state and when you update the redux state document.title will be update as well.

This allows you to deal with the document.title consistent with redux. You just alter state using actions and reducers and get state containing the title from the redux store.

The library was created because of my complete cluelessness how to deal with changing titles in a redux/react-router application. As it seems I was not the only one who had no clue, I tried my best and created this very simple piece of code.

It is inspired by the way redux-simple-router works and the first version is also based on a copy of the source of that library. So, kudos to James!

How to Use It

The main idea is very simple:

  • add mutual listeners to redux store and document.title
  • call an action creator that changes redux state
  • get the title through the redux store like any other state
  • automatically get updates of the initial or changed document.title

There is not a lot of documentation, yet. Check out this simple example which is part of this repository. The tests also are a good example of how to use this lib.

Here is a little bit of code from the example how to set up redux-title:

import React from 'react'
import ReactDOM from 'react-dom'
import { createStore, combineReducers } from 'redux'
import { titleReducer, syncReduxAndTitle } from 'redux-title'
import { Provider } from 'react-redux'

const store = createStore(combineReducers({
    title: titleReducer
}));

syncReduxAndTitle(store);

import HelloMessage from './HelloMessage'

React.render(
  <Provider store={store}>
    <HelloMessage />
  </Provider>,
  document.getElementById('mount')
)

And this is how you can display and change the title:

import React from 'react'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'

class HelloMessage extends React.Component {
    render() {
        const {title, updateTitle} = this.props;
        return (
            <div>
                <input ref="in"
                       onChange={event => updateTitle(event.target.value)}
                       value={title} />
                <p>{title}</p>
                <button
                    onClick={() => {
                        updateTitle('');
                        this.refs.in.focus();
                    }}>
                    Clear
                </button>
            </div>);
    }
}
import {updateTitle} from 'redux-title'

function mapStateToProps(state) {
    return {
        title: state.title
    };
}

function mapDispatchToProps(dispatch) {
    return bindActionCreators({updateTitle}, dispatch);
}

export default connect(mapStateToProps, mapDispatchToProps)(HelloMessage);