npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-three-viewer

v0.0.5

Published

React Three.js 3D model viewer

Downloads

127

Readme

react-three-viewer

Greenkeeper badge

A simple library to view 3d models in react app build with three.js

codesandbox exampe

Installation

It requires three.js library to work

npm install react-three-viewer three

How to use

import { useViewer } from 'react-three-viewer';

const App: React.FC = () => {
  const [binds, { load }] = useViewer();

  const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
    const fileList = event.target.files;

    if (!fileList) {
      return;
    }

    const file = fileList[0];

    if (!file) {
      return;
    }

    load(file);
  };

  return (
    <div className="App">
      <header className="App__header">
        <h2>Upload 3d Model</h2>
      </header>

      <section className="files">
        <input type="file" onChange={handleFileChange} />
      </section>

      <section>
        <div className="viewer" ref={binds} />
      </section>
    </div>
  );
};

Hook API Methods

const { load, fetch } = useViewer();
  • load(file: File) - Load 3d file and add it to scene
  • fetch(url: string) - Fetch 3d file by http and add it to scene

Hook Config

const {} = useViewer(elementRef);
  • elementRef - Ref to element for viewer to append

How to solve problems

VS Code linter dont lint *.ts files

  • Open VS config Ctrl + Shift + P and type >Preferences: Open Settings (JSON)
  • Add next configs:
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    "typescript",
    "typescriptreact"
  ]

no-unused-vars ESLint error

The issue is that typescript-eslint/no-unused-vars simply tag types and interfaces (that are imported or defined in the file) as unused, even if they are. Well for my specific case I ended up with this workaround

overrides: [
  {
    files: ['*.ts', '*.tsx'],
    rules: {
      '@typescript-eslint/no-unused-vars': [2, { args: 'none' }],
    },
  },
];