redux

Redux loses state when navigating to another page

淺唱寂寞╮ 提交于 2019-12-25 09:35:37
问题 I am building a web application using React and Redux. Redux works when I set the state on that page and then reaccess it through a statement like this.props.book.bookTitle , however, when I navigate to another page, redux loses it's state and defaults to the initialState. Here is my code: bookDuck.js: const BOOK_SELECT = "book/SELECT"; const BOOK_DESELECT = "book/DESELECT"; const initialState = { _id: "", bookTitle: "", bookCover: "", bookAuthors: [], bookDescription: "" }; export default

Same tab content is being displaying twice

▼魔方 西西 提交于 2019-12-25 09:17:20
问题 I have implemented a simple tabs code. I am trying to move the tabs container inside my li tag, since its a new requirement. After changing the code the same tab content is being displaying twice. _renderTitles: function () { function labels(child, index) { var activeClass = (this.state.selected === index ? 'active' : ''); return ( <li role="presentation" key={index} className={child.props.liClass}> <a href="#" className={`sports-tab-header ${activeClass}`} onClick={this.handleClick.bind(this

React Redux passing parameters via functions from child components to parent

坚强是说给别人听的谎言 提交于 2019-12-25 09:09:07
问题 I asked a question on this and I believe Dennis who answered the question gave the answer I thought was correct. I cant figure out how to pass variables back to the parent function correctly... Here is the code I want to fix. Child of a Child Component First there is a child of a child component. This will set the sort direction of the list if you click on it. Its using "onSortDirectionChange" function and should set the sort direction by setting a variable "sortDirection". const

How to find the file where my React/Redux error is coming from?

前提是你 提交于 2019-12-25 09:01:14
问题 I'm using webpack to compile my React/Redux app. It's throwing an error on screen in the browser (red screen), but not in the console. Is there a way to configure webpack to point to the exact component/container (file) where it's running into this error? Here is the error I'm getting: Error: bindActionCreators expected an object or a function, instead received undefined. Did you write "import ActionCreators from" instead of "import * as ActionCreators from"? bindActionCreators http:/

react-router url change but had to double click “Link” component for ui to change

做~自己de王妃 提交于 2019-12-25 08:05:13
问题 When loading for the first time the content is displayed correctly, clicking a link will change the URL but the view still the same. I had to click twice for the view to change. My router render( <Provider store={store}> <Router history={browserHistory}> <Route path="/:courseName/**" component={components.app}> <IndexRoute components={{ sidebar: containers.sidebar, chapter: containers.chapter }} /> </Route> </Router> </Provider>, document.getElementById('container') ); My dispatch inside the

login api request using react and redux

对着背影说爱祢 提交于 2019-12-25 07:58:57
问题 I'm trying to make a small project using react & redux . The Main page for this project is the login . I already have a working api for login. Below is the code snippets from my project: login.js onLoginFormSubmit(event) { event.preventDefault(); this.props.actions.login(this.state.username, this.state.password); } render() { return ( ...Login Form ... ); } } Login.propTypes = { actions: PropTypes.object.isRequired, }; function mapStateToProps(state, ownProps) { return { loginResponse: state

React Native/Redux: How to pass down updated state to child components every time state changes?

拟墨画扇 提交于 2019-12-25 07:44:15
问题 In React Native and Redux, I am using <NavigationCardStack/> as the root component and render routes with _renderScene() . But seems like whenever the root component re-renders with state update, it does not pass the state down every update, because I put console.log(this.props) in the child component and logs the passed state, but it only logs once and that is the first time the app starts up and never logs after even if the root component re-renders with the state update. Why isn't it

Having problems causing re-render with boolean variables in my state object

蓝咒 提交于 2019-12-25 06:58:17
问题 So I have a couple boolean variables in my state to control visibility of certain elements in my ui and I try to toggle it by dispatching an action through a button onClick but it doesn't seem to be working... container component import { connect } from 'react-redux' import { toggleUnexcusedAbsences, toggleUnexcusedTardies, toggleExcused } from '../actions' import AttendanceDetails from '../components/AttendanceDetails' const mapStateToProps = (state) => { console.log('state:', state);

Altering react form but input value not editable

僤鯓⒐⒋嵵緔 提交于 2019-12-25 06:51:51
问题 I came from angularjs background, with 2 way binding I don't have to worry much, just declare a submit function, I can get the changed or unchanged value. I'm stuck with react now. My input is not editable. class HelloWorldComponent extends React.Component { constructor(){ super(); this.handleChange = this.handleChange.bind(this) } render() { const person = {"name":"james"}; return ( <input onChange={this.handleChange} type="text" placeholder="name" value={person.name} /> ); } handleChange(e)

Why receiving error 'should be push route with duplicated key' with Regact Native's NavigationExperimental?

断了今生、忘了曾经 提交于 2019-12-25 06:42:34
问题 My navigation reducer set up as such: const { StateUtils: NavigationStateUtils } = NavigationExperimental const initialState = { index: 0, key: 'root', routes: [{ key: 'login', title: 'Login', component: Login }] } function navigationState (state = initialState, action) { switch(action.type) { case PUSH_ROUTE: if (state.routes[state.index].key === (action.route && action.route.key)) return state return NavigationStateUtils.push(state, action.route) case POP_ROUTE: if (state.index === 0 ||