Home javascript REACT item does not see the store

REACT item does not see the store

Author

Date

Category

I write a test application on REACT, my component does not see the store transmitted through the provider

import './secret.css'
Import {Connect} from 'React-Redux'
Import login from '../../actions/actions';
Const Secret = ({Store}) = & gt; {
  Console.log (Store.getState ())
  Return (
    & lt; div classname = "secret" & gt;
      & lt; h1 classname = "secret__title-nologin" & gt; You are not logined & lt; / h1 & gt;
    & lt; / div & gt;
  );
};
Const MapStateToproprops = (state) = & gt; {
  Return {
    islogin: state.islogin,
  }
}
Const MapDispatchTopropropros = {login}
Export Default Connect (MapStatetoproprops, MapDispatchTopropros) (Secret);

My index, which in ideas should transfer the store to the whole project

import react from 'react';
Import ReactDom from 'React-Dom';
Import {provider} from 'react-redux';
Import {browserrouter} from 'react-router-dom';
Import Store from '../../login-app/src/store'
Import app from './components/app';
Console.log ('index.js');
Reactdom.render (
  & lt; provider store = {Store} & gt;
    & lt; browserrouter & gt;
      & lt; app / & gt;
    & lt; / browserrouter & gt;
  & lt; / provider & gt;
  ,
  Document.GetElementByid ('root')
);

My reduser

const initialstate = {
  Islogin: False.
};
const Reduser = (State = InitialState, Action) = & gt; {
  Switch (Action.Type) {
    Case 'user_login':
      Return {
        Islogin: True.
      }
    Default:
      Return State
  }
}
EXPORT DEFAULT REDUSER;

Answer 1

You subscribe through mapstatetoproprips to the izlogin key here and output it in the console

const secret = ({islogin}) = & gt; {
  Console.log (Islogin)
  Return (
    & lt; div classname = "secret" & gt;
      & lt; h1 classname = "secret__title-nologin" & gt; You are not logined & lt; / h1 & gt;
    & lt; / div & gt;
  );
};

If you want to get the whole store , then mapstatetoproprips rewrite like this:

const mapstatetoproproprps = (state) = & gt; {
  Return {
    State: State,
  }
}

and output in the console:

const secret = ({state}) = & gt; {
  Console.log (State) // getstate () do not need
  Return (
    & lt; div classname = "secret" & gt;
      & Lt; h1 className = "secret__title-nologin" & gt; You are not logined & lt; / h1 & gt;
    & lt; / div & gt;
  );
};

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions