
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
react-navigation-sxf-redux-helpers
Advanced tools
Redux middleware and utils for React Navigation
This package allows the user to manage their React Navigation state from within Redux.
Most projects that are using both Redux and React Navigation don't need this library. Things like state persistence and BackHandler
behavior aren't handled directly by createReduxContainer
, but are handled by the default createAppContainer
. However, there are some things this library makes easier:
isTransitioning
to true!)yarn add react-navigation-redux-helpers
or
npm install --save react-navigation-redux-helpers
import {
createStackNavigator,
} from 'react-navigation';
import {
createStore,
applyMiddleware,
combineReducers,
} from 'redux';
import {
createReduxContainer,
createReactNavigationReduxMiddleware,
createNavigationReducer,
} from 'react-navigation-redux-helpers';
import { Provider, connect } from 'react-redux';
import React from 'react';
const AppNavigator = createStackNavigator(AppRouteConfigs);
const navReducer = createNavigationReducer(AppNavigator);
const appReducer = combineReducers({
nav: navReducer,
...
});
const middleware = createReactNavigationReduxMiddleware(
state => state.nav,
);
const App = createReduxContainer(AppNavigator);
const mapStateToProps = (state) => ({
state: state.nav,
});
const AppWithNavigationState = connect(mapStateToProps)(App);
const store = createStore(
appReducer,
applyMiddleware(middleware),
);
class Root extends React.Component {
render() {
return (
<Provider store={store}>
<AppWithNavigationState />
</Provider>
);
}
}
createReactNavigationReduxMiddleware
(required)function createReactNavigationReduxMiddleware<State: {}>(
navStateSelector: (state: State) => NavigationState,
key?: string,
): Middleware<State, *, *>;
navStateSelector
selects the navigation state from your store.key
needs to be unique for the Redux store and consistent with the call to createReduxContainer
below. You can leave it out if you only have one store.createReduxContainer
(required)function createReduxContainer(
navigator: Navigator,
key?: string,
): React.ComponentType<{ state: NavigationState, dispatch: Dispatch }>;
navigator
is your root navigator (React component).key
needs to be consistent with the call to createReactNavigationReduxMiddleware
above. You can leave it out if you only have one store.state
and dispatch
props that you get via react-redux
's connect
.createNavigationReducer
(optional)function createNavigationReducer(navigator: Navigator): Reducer<*, *>;
createNavigationReducer
in the global scope to construct a navigation reducer.navigator.router.getStateForAction
, which you can call directly if you'd prefer.navigator
is your root navigator (React component).combineReducers
.To make Jest tests work with your React Navigation app, you need to change the Jest preset in your package.json
:
"jest": {
"preset": "react-native",
"transformIgnorePatterns": [
"node_modules/(?!(jest-)?react-native|@?react-navigation|react-navigation-redux-helpers)"
]
}
Here is a code snippet that demonstrates how the user might handle the hardware back button on platforms like Android:
import React from "react";
import { BackHandler } from "react-native";
import { NavigationActions } from "react-navigation";
/* your other setup code here! this is not a runnable snippet */
class ReduxNavigation extends React.Component {
componentDidMount() {
BackHandler.addEventListener("hardwareBackPress", this.onBackPress);
}
componentWillUnmount() {
BackHandler.removeEventListener("hardwareBackPress", this.onBackPress);
}
onBackPress = () => {
const { dispatch, nav } = this.props;
if (nav.index === 0) {
return false;
}
dispatch(NavigationActions.back());
return true;
};
render() {
/* more setup code here! this is not a runnable snippet */
return <AppNavigator navigation={navigation} />;
}
}
FAQs
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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.