![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
connect-alt
Advanced tools
Decorator for passing alt store state through props, heavily inspired from
react-redux::connect
$ npm i -S connect-alt
Use AltContainer for an easy integration:
import { render } from 'react-dom';
import AltContainer from 'alt-container';
import Flux from './Flux';
import App from './App';
render(<AltContainer flux={ new Flux() }><App /></AltContainer>);
This is the most performant way, it only listen for the specific store changes and not waiting for all stores to update
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import connect from 'connect-alt';
@connect('session')
class Example extends Component {
static propTypes = { sessionStore: PropTypes.object.isRequired }
render() {
const { sessionStore: { currentUser } } = this.props;
return (
<pre>{ JSON.stringify(currentUser, null, 4) }</pre>
);
}
}
You can pass as many stores you want to the decorator: @connect('session', 'posts', 'foo', 'bar')
, you will get them into props with the suffix Store
.
Warning, this is expensive because connect-alt
will be listening for any stores update and not the only concerned
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import connect from 'connect-alt';
@connect(({ session: { currentUser } }) => ({ currentUser }))
class Example extends Component {
static propTypes = { currentUser: PropTypes.object.isRequired }
render() {
const { currentUser } = this.props;
return (
<pre>{ JSON.stringify(currentUser, null, 4)</pre>
);
}
}
NOTE: You will need to provide a FinalStore
on alt instance:
import Alt from 'alt';
import makeFinalStore from 'alt/utils/makeFinalStore';
class Flux extends Alt {
constructor(config) {
super(config);
this.FinalStore = makeFinalStore(this);
}
}
export default Flux;
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import connect from 'connect-alt';
@connect('session', ({ session: { currentUser } }) => ({ currentUser }))
class Example extends Component {
static propTypes = { currentUser: PropTypes.object.isRequired }
render() {
const { currentUser } = this.props;
return (
<pre>{ JSON.stringify(currentUser, null, 4)</pre>
);
}
}
See isomorphic-flux-boilerplate for a complete app example.
FAQs
Decorator for passing Altjs store state through props
The npm package connect-alt receives a total of 13 weekly downloads. As such, connect-alt popularity was classified as not popular.
We found that connect-alt demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.