Giter Site home page Giter Site logo

Comments (3)

nuxy avatar nuxy commented on June 11, 2024

Without seeing your code, but based on the error message itself, it looks like your missing the react-dom NPM package.

For example, the head of your component should look like..

import React       from 'react';
import ReactDOM    from 'react-dom';
import SlotMachine from 'react-slot-machine';

Hope this helps.

from react-slot-machine-gen.

topmagician avatar topmagician commented on June 11, 2024

Thanks for your response.
I am going to define the slot machine component and import it in index.tsx file.
Here is the component I made with your npm module.
It still shows the same error.
I already made the image file in the specified folder in this code.

import { useState } from 'react';
// @ts-ignore
import SlotMachine from 'react-slot-machine-gen'; // or '../dist/react-slot-machine-gen';

const SlotMachineWrapper = () => {
    const [isPlaying, setIsPlaying] = useState(false);

    const playEvent = () => {
        setIsPlaying(!isPlaying);
    }

    const reels = [
        {
            imageSrc: 'images/slot_bg.png',
            symbols: [
                {
                    title: 'cherry',
                    position: 100,
                    weight: 2
                },
                {
                    title: 'plum',
                    position: 300,
                    weight: 6
                },
                {
                    title: 'orange',
                    position: 500,
                    weight: 5
                },
                {
                    title: 'bell',
                    position: 700,
                    weight: 1
                },
                {
                    title: 'cherry',
                    position: 900,
                    weight: 3
                },
                {
                    title: 'plum',
                    position: 1100,
                    weight: 5
                }
            ]
        },

        // add more reels ...
    ]

    return (
        <>
            <SlotMachine reels={reels} play={isPlaying} />
            <button id="play-button" onClick={() => playEvent()}>Play</button>
        </>
    );
};

export default SlotMachineWrapper;

from react-slot-machine-gen.

nuxy avatar nuxy commented on June 11, 2024

FYI, this is not an issue with this package but an issue with your app configuration.

That being said, here is how you can overcome this.

Create new React application

$ create-react-app slot-machine-test
$ npm run eject
$ npm install react-slot-machine-gen

Update webpack.config.js

            // Process any JS outside of the app with Babel.
            // Unlike the application JS, we only compile the standard ES features.
            {
              test: /\.(js|mjs)$/,
              exclude: /@babel(?:\/|\\{1,2})runtime/,
              loader: require.resolve('babel-loader'),
              options: {
                babelrc: false,
                configFile: false,
                compact: false,
                presets: [
+                  ["@babel/preset-env"],
+                  ["@babel/preset-react", {"runtime": "automatic"}],

.. and then

     // Turn off performance processing because we utilize
     // our own hints via the FileSizeReporter
     performance: false,
+    resolve: {
+      alias: {
+        react: path.resolve('./node_modules/react'),
+      }
+    }
   };
};

Closing this issue.

from react-slot-machine-gen.

Related Issues (5)

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.