icd2k3/react-router-breadcrumbs-hoc

TypeError: Object(...) is not a function

Closed this issue · 9 comments

I am trying use this package but I am
getting this error when I try to run the code you have posted in the Example.
screenshot-2017-12-27 honeyguide apps
I am importing Breadcrumbs and rendering <Breadcrumbs/>. Is this not the way to do it?

Hey @ShadyXV could you please post your full source code for the file you're using the HOC in? Also, showing the full error details ("15 stack frames were collapsed") could help.

I'm on vacation currently, but should have time to check on this during my travels.

Thanks!

Thank you for responding so quickly.Here is the full error detail.
screenshot-2017-12-27 honeyguide apps 1
I am not passing any props to Breadcrumbs is this where i am going wrong.

The hoc will automatically pass a breadcrumbs prop into the wrapped component. You can pass additional props if you like, but it shouldn't matter in terms of rendering. When you have a moment could you paste the full source of Breadcrumbs/index.jsx? Thanks

Breadcrumbs/index.jsx looks like this

import React from "react";
import { NavLink } from "react-router-dom";
import { withBreadcrumbs } from "react-router-breadcrumbs-hoc";

const UserBreadcrumb = ({ match }) => <span>{match.params.userId}</span>; // use match param userId to fetch/display user name

const routes = [
  { path: "/", breadcrumb: "Home" },
  { path: "users", breadcrumb: "Users" },
  { path: "users/:userId", breadcrumb: UserBreadcrumb },
  { path: "something-else", breadcrumb: ":)" }
];

const Breadcrumbs = ({ breadcrumbs }) => (
  <div>
    {breadcrumbs.map(({ breadcrumb, path, match }) => (
      <span key={path}>
        <NavLink to={match.url}>{breadcrumb}</NavLink>
        <span>/</span>
      </span>
    ))}
  </div>
);

export default withBreadcrumbs(routes)(Breadcrumbs);

I trying rendering Breadcrumbs in different ways but even just importing it fails with the same errors.
I am importing Breadcrumbs from Breadcrumbs/index.jsx like so
import Breadcrumbs from './components/Breadcrumbs';
i am using this in a create-react-app project, react v16.2.0, react-router-dom v4.2.2

Hey @ShadyXV I'll have to take a closer look at this in the near future. Not quite sure what might be happening as of yet.

The build process recently switched (PR: #9) ... I wonder if there is possibly some unintended side effects from that. Could you try downgrading npm i react-router-breadcrumbs-hoc@1.0.7 and see if that fixes the issue?

Yup. You are right.It's working now.Thank you.
I'll use react-router-breadcrumbs-hoc@1.0.7 for now.
Happy Holidays!

Thanks @ShadyXV I was able to repro your issue using create-react-app myself. I'll look into fixing the issue and close this thread with v 1.1.1 when fixed!

Edit: pinging @mhelmer who might have some suggestions here.

This one took a while to figure out, but seems the create-react-app config has trouble with .mjs file extensions. I've changed the build output in v 1.1.1 here: #14

This should fix the issue, can you confirm on your end everything is still working @ShadyXV after upgrading from 1.0.7 to 1.1.1?