GithubHelp home page GithubHelp logo

adamerose / muuri-react Goto Github PK

View Code? Open in Web Editor NEW

This project forked from paol-imi/muuri-react

4.0 4.0 4.0 35.45 MB

The layout engine for React

Home Page: https://paol-imi.github.io/muuri-react/

License: MIT License

JavaScript 25.96% TypeScript 71.41% CSS 2.64%

muuri-react's People

Contributors

adamerose avatar in-dev-paolo avatar paol-imi avatar secretmapper avatar xeonax avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

muuri-react's Issues

TypeError: Cannot read properties of undefined (reading 'key')

Hello I'm using this version of muuri for use a react 17.0.2

But i have simply code and i have error when i move grid between Muuri components:
image

image

Is in fresh app react

import { useState, useCallback } from "react";
import { MuuriComponent, useGrid } from "muuri-react";

function useSend(setItems) {
  return useCallback(({ key, fromId, toId }) => {
    fromId = fromId.toLowerCase();
    toId = toId.toLowerCase();
    setItems((items) => {
      const newItems = { ...items };
      newItems[fromId] = newItems[fromId].filter((item) => item !== key);
      newItems[toId] = newItems[toId].concat(key);
      return newItems;
    });
  }, [setItems]);
}

const columnOptions = {
  // Enable to send the items in
  // the grids with the following groupId.
  dragSort: { groupId: "NOTES" },
  groupIds: ["NOTES"],
  containerClass: "board-column-content",
  dragEnabled: true,
  dragFixed: true,
  dragSortHeuristics: {
    sortInterval: 0,
  },
  dragContainer: document.body,
};

// App.
const App = () => {
  // Items state.
  const [items, setItems] = useState({
    todo: ["4", "6", "5", "10"],
    working: ["1", "3", "8"],
    done: ["2", "7", "9"],
  });

  const onSend = useSend(setItems);

  // Children.
  const children = {
    todo: items.todo.map((id) => <Item id={id} key={id} />),
    done: items.done.map((id) => <Item id={id} key={id} />),
    working: items.working.map((id) => <Item id={id} key={id} />),
  };

  const borderStyle = {
    width: "100%",
    height: "100px",
    padding: "10px",
    border: "2px dashed gray",
    borderRadius: "5px",
    overflowY: "scroll",
  };

  return (
    <div>
      <div style={borderStyle}>
        Muuri Component 1
        <MuuriComponent
          id={"TODO"}
          onSend={onSend}
          sort={items.todo}
          {...columnOptions}
        >
          {children.todo}
        </MuuriComponent>
      </div>
      <div style={borderStyle}>
        Muuri Component 2
        <MuuriComponent
          id={"WORKING"}
          onSend={onSend}
          sort={items.working}
          {...columnOptions}
        >
          {children.working}
        </MuuriComponent>
      </div>
      <div style={borderStyle}>
        Muuri Component 3
        <MuuriComponent
          id={"DONE"}
          onSend={onSend}
          sort={items.done}
          {...columnOptions}
        >
          {children.done}
        </MuuriComponent>
      </div>
    </div>
  );
};

const Item = ({ id }) => {
  const gridId = useGrid().id.toLowerCase();
  return (
    <div className="board-item">
      <div className="board-item-content">
        <span>Item </span>
        {`${id} - XXX`}
        <div className={`tab-item ${gridId}-tab-item`} />
      </div>
    </div>
  );
};

export default App;

The package.json is a fresh react app:

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "muuri-react": "github:adamerose/muuri-react",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-scripts": "4.0.3",
    "web-vitals": "^1.0.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

Any idea if i'm doing wrong something? seems a muuri-react bug

Random error "You can only create one Muuri Item per element!"

Thank you for forking this and making it install compatible with React 17.

I get this error "You can only create one Muuri Item per element!" randomly even when then are no changes to the code, just with a file save and even after a full page refresh.

The error is originated from here muuri/src/Item/Item.js#L39 and it seems it's something new in muuri 0.9 to cache the items used.

I forked your repo and changed:

"peerDependencies": {
  "muuri": "^0.8.0 || ^0.9.0",
  "react": "^17.0.2"
},

to allow install muuri 0.8 and it seems like it's working fine so far without this issue.
I even looked at 0.8 code and there is no such mechanist nor that error thrown.

Do you have a clue how to fix this issue so to make it muuri 0.9 compatible?
The most strange part is that the error occurs even after a full page reload!
I think muuri-react should install with muuri 0.8 until this issue gets sorted.

Notes about this fork

Since Paol-imi/muuri-react is unmaintained, I took the changes made in https://github.com/Secretmapper/muuri-react/tree/strict-muuri-0.9 and merged them to master and fixed package.json on this fork. I will accept any new PRs made here.

The maintenance status of the original repo is discussed here: paol-imi#59

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.