react-redux#connect JavaScript Examples

The following examples show how to use react-redux#connect. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Editor.js    From scalable-form-platform with MIT License 6 votes vote down vote up
XFormBuilder = connect((store, ownProps) => {
    const namespace = ownProps.namespace;
    if (typeof namespace === 'undefined' || namespace === '') {
        console.warn('xformBuilder:使用xformBuilder组件建议传入唯一性的namespace属性,否则会因为store数据共享导致问题');
    }
    return {
        xformBuilderData: store.xformBuilderData[namespace] || store.xformBuilderData
    };
})(contextWrapper(localeMessagesWrapper(APP)))
Example #2
Source File: RequireAuthentication.js    From Lambda with MIT License 6 votes vote down vote up
export default function RequireAuthentication(Component) {
  class Authentication extends React.Component {
    render() {
      return (
        <Route
          render={(props) => {
            return this.props.isAuthenticated ? (
              <Component {...props} />
            ) : (
              <Redirect
                to={{
                  pathname: "/login",
                  state: { from: props.location },
                }}
              />
            );
          }}
        />
      );
    }
  }

  Authentication.propTypes = {
    isAuthenticated: PropTypes.bool,
  };

  function mapStateToProps(state) {
    return {
      isAuthenticated: state.user.isAuthenticated,
    };
  }

  return withRouter(connect(mapStateToProps)(Authentication));
}
Example #3
Source File: index.js    From nextjs-boilerplate with MIT License 6 votes vote down vote up
authenticatedRoute = (Component = null, options = {}) => {
  class AuthenticatedRoute extends React.Component {
    state = {
      loading: true,
    };

    componentDidMount() {
      if (this.props.isLoggedIn) {
        this.setState({ loading: false });
      } else {
        Router.push(
          options.pathAfterFailure ||
            settings?.routes?.authenticated?.pathAfterFailure
        );
      }
    }

    render() {
      const { loading } = this.state;

      if (loading) {
        return <div />;
      }

      return <Component {...this.props} />;
    }
  }

  return connect((state) => ({
    isLoggedIn: state?.authenticated && !!state?.user,
  }))(AuthenticatedRoute);
}
Example #4
Source File: embedded-terminal.js    From ThreatMapper with Apache License 2.0 6 votes vote down vote up
render() {
    const { pipe, details } = this.props;
    const nodeId = pipe.get('nodeId');
    const node = details.get(nodeId);
    const d = node && node.details;
    const titleBarColor = d && getNodeColorDark(d.rank, d.label, d.pseudo);
    const statusBarColor = d && brightenColor(titleBarColor);
    const title = d && d.label;

    // React unmount/remounts when key changes, this is important for cleaning up
    // the term.js and creating a new one for the new pipe.
    return (
      <div className="tour-step-anchor terminal-embedded">
        <div
          onTransitionEnd={this.handleTransitionEnd}
          className="terminal-animation-wrapper"
          style={{transform: this.getTransform()}}>
          <Terminal
            key={pipe.get('id')}
            pipe={pipe}
            connect={this.state.animated}
            titleBarColor={titleBarColor}
            statusBarColor={statusBarColor}
            title={title} />
        </div>
      </div>
    );
  }
Example #5
Source File: withHashLink.js    From volto-slate with MIT License 6 votes vote down vote up
export function withHashLink(WrappedComponent) {
  return connect(
    (state) => {
      return {
        hashlink: state.hashlink,
      };
    },
    { setHashLink, resetHashLink },
  )((props) => {
    return (
      <WrappedComponent
        {...props}
        setHashLink={props.setHashLink}
        resetHashLink={props.resetHashLink}
      />
    );
  });
}
Example #6
Source File: AuthenticatedComponent.js    From YApi-X with MIT License 6 votes vote down vote up
export function requireAuthentication(Component) {
  return @connect(
    state => {
      return {
        isAuthenticated: state.user.isLogin
      };
    },
    {
      changeMenuItem
    }
  )
  class AuthenticatedComponent extends React.PureComponent {
    constructor(props) {
      super(props);
    }
    static propTypes = {
      isAuthenticated: PropTypes.bool,
      location: PropTypes.object,
      dispatch: PropTypes.func,
      history: PropTypes.object,
      changeMenuItem: PropTypes.func
    };
    componentWillMount() {
      this.checkAuth();
    }
    componentWillReceiveProps() {
      this.checkAuth();
    }
    checkAuth() {
      if (!this.props.isAuthenticated) {
        this.props.history.push('/');
        this.props.changeMenuItem('/');
      }
    }
    render() {
      return <div>{this.props.isAuthenticated ? <Component {...this.props} /> : null}</div>;
    }
  };
}
Example #7
Source File: Extension.jsx    From mapstore2-cadastrapp with GNU General Public License v3.0 6 votes vote down vote up
Cadastrapp = compose(
    connect((state) => ({
        enabled: state.controls && state.controls[CONTROL_NAME] && state.controls[CONTROL_NAME].enabled || false,
        dockStyle: mapLayoutValuesSelector(state, { right: true, height: true}, true),
        dockWidth: 550,
        withButton: false
    }), {
        open: () => toggleControl(CONTROL_NAME, "enabled", true),
        onClose: () => toggleControl(CONTROL_NAME, "enabled", false)
    }),
    // setup and teardown due to open/close
    compose(
        connect( () => ({}), {
            setUp
        }),
        init()
    )
)(Main)
Example #8
Source File: connect.js    From mixbox with GNU General Public License v3.0 6 votes vote down vote up
export default function defaultConnect({actions, options}) {
    return function connectComponent(component) {
        const {
            mapStateToProps = () => ({}),
            mapDispatchToProps = (dispatch) => {
                const ac = bindActionCreators(actions, dispatch);
                Object.keys(actions).forEach(key => {
                    if (typeof actions[key] === 'object') {
                        ac[key] = bindActionCreators(actions[key], dispatch);
                    }
                });

                return {action: ac};
            },
            mergeProps,
            LayoutComponent,
        } = component;

        // 只要组件导出了mapStateToProps,就说明要与redux进行连接
        // 优先获取LayoutComponent,如果不存在,获取default
        if (mapStateToProps) {
            let com = LayoutComponent || component.default;
            if (!com) return component;
            return connect(
                mapStateToProps,
                mapDispatchToProps,
                mergeProps,
                options
            )(com);
        }
        return LayoutComponent || component.default || component; // 如果 component有多个导出,优先LayoutComponent,其次使用默认导出
    };
}
Example #9
Source File: DeckEditor.jsx    From ashteki with GNU Affero General Public License v3.0 5 votes vote down vote up
DeckEditor = connect(mapStateToProps, actions)(InnerDeckEditor)
Example #10
Source File: auth-form.js    From Changes with MIT License 5 votes vote down vote up
Login = connect(mapLogin, mapDispatch)(AuthForm)
Example #11
Source File: atmMenu.jsx    From CyberStateRP with MIT License 5 votes vote down vote up
connected = connect(mapStateToProps)(AtmMenu)
Example #12
Source File: index.js    From QiskitFlow with Apache License 2.0 5 votes vote down vote up
withConnect = connect(
  mapStateToProps,
  mapDispatchToProps,
)
Example #13
Source File: Comment.jsx    From archeage-tools with The Unlicense 5 votes vote down vote up
ConnectedComment = connect(null, mapDispatchToProps)(Comment)
Example #14
Source File: index.js    From gatsby-ipfs-web-wallet with MIT License 5 votes vote down vote up
ConnectedDashboard = AdminLTE
  ? connect(mapStateToProps, mapDispatchToProps)(AdminLTE)
  : null
Example #15
Source File: LoginControl.js    From aws-workshop-colony with Apache License 2.0 5 votes vote down vote up
connectStateAndProps = connect(
  mapStateToProps,
  mapDispatchToProps
)
Example #16
Source File: component_1_w.js    From Basical-react-redux-app with MIT License 5 votes vote down vote up
COMPONENT_1_W = connect(mapStateToProps("Component_1"), mapDispatchToProps("Component_1"))(Component_1)
Example #17
Source File: TextInput.js    From bicara-hook with GNU General Public License v3.0 5 votes vote down vote up
ConnectedTextInput = connect(
  null,
  mapDispatchToProps
)(TextInput)
Example #18
Source File: SocketProviderMock.js    From flatris-LAB_V1 with MIT License 5 votes vote down vote up
SocketProviderMock = connect()(SocketProvider)
Example #19
Source File: AppContainer.js    From FEC with MIT License 5 votes vote down vote up
AppContainer = connect(mapStoreToProps, mapDispatchToProps)(App)
Example #20
Source File: index.js    From strapi-molecules with MIT License 5 votes vote down vote up
withConnect = connect(mapStateToProps, mapDispatchToProps)
Example #21
Source File: requiresAuth.js    From voicemail-for-amazon-connect with Apache License 2.0 5 votes vote down vote up
export default function (ComposedComponent, UnauthedComponent) {
    class Authenticate extends React.Component {
        constructor(props) {
            super(props);
            this.state = {
                authState: 'loading'
            }
        }

        componentDidMount() {
            this._checkAndRedirect();
        }

        componentDidUpdate() {
            this._checkAndRedirect();
        }

        _checkAndRedirect() {
            if (this.state.authState === "loading") {
                Auth.currentAuthenticatedUser().then(user => {
                    this.props.auth(user);
                    this.setState({authState: 'valid'});
                }).catch(e => {
                    this.setState({authState: 'invalid'});
                    this.props.redirect();
                });
            }
        }

        render() {
            return this.state.authState === 'valid' ?
                <ComposedComponent {...this.props} /> : <UnauthedComponent {...this.props}/>;
        }
    }

    const mapStateToProps = (state) => {
        return {
            auth: state.auth
        };
    };

    const mapDispatchToProps = (dispatch) => {
        return {
            redirect: () => dispatch(() => {history.push("/login")}),
            auth: (user) => dispatch(AuthAction.auth(user))
        }
    };

    return connect(
        mapStateToProps,
        mapDispatchToProps
    )(Authenticate);
}
Example #22
Source File: AlbumContainer.js    From spotify-react with MIT License 5 votes vote down vote up
connectAlbum = connect(
  mapStateToProps,
  mapDispatchToProps
)
Example #23
Source File: auth.connect.js    From React-Native-Boilerplate with MIT License 5 votes vote down vote up
export function authData(configMapStateToProps = mapStateToProps) {
  return connect(configMapStateToProps, mapDispatchToProps);
}
Example #24
Source File: AddTodo.js    From Learning-Redux with MIT License 5 votes vote down vote up
AddTodo = connect()(AddTodo);