Skip to content
This repository was archived by the owner on Oct 26, 2018. It is now read-only.
This repository was archived by the owner on Oct 26, 2018. It is now read-only.

Invariant Violation: Unable to find element when using middleware and conditionally rendering <Link> #294

Closed
@j

Description

@j

I'm just reviving the issue that the original person closed #244.

Basically he has a gist that shows the steps he took to fix the error. @0x80 mentioned that removing the reducer fixes the problem, and I want to also confirm that removing it causes the app to work, which leads me to believe that it has something to do with this library.

I basically have (this won't obviously work copy/paste):

import React, { Component, PropTypes } from 'react';
import { Link } from 'react-router';

class Pagination extends Component {
  linkTo(label, page) {
    const { total, to } = this.props;
    const href = to + page;

    if (page < 1 || page > total) {
      return null;
    }

    return <Link to={href}>{label}</Link>;
  }

  render() {
    const { current } = this.props;

    return (
      <div className={styles.this}>
        {this.linkTo('Previous', current - 1)}
        {this.linkTo('Next', current + 1)}
      </div>
    );
  }
}

Pagination.propTypes = {
  to: PropTypes.string.isRequired,
  current: PropTypes.number,
  total: PropTypes.number,
};

const routes =  (
  <Route path="/" component={App}>
    <IndexRoute component={Home} />
    <Route path="pages(/:page)" component={Category} />
  </Route>
);

const reducers = combineReducers({
  entities,
  routing,
});

Then when I visit /pages root, then click then it only renders the "Next" button. Clicking "Next" throws the error.

A way around it initially was for me to not return null on the Previous link and to just do a "display: none" on it, which fixed the issue. Then I tried doing the things in #244 and things broke. Then I reverted back to my original code but removed this library since I'm not yet using it, and it works.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions