# Example of React with Hooks integration, and how to build for production

**URL:** <https://devforum.zoom.us/t/example-of-react-with-hooks-integration-and-how-to-build-for-production/18936>\
**Category:** Web\
**Created:** [May 25, 2020, 5:22am UTC](https://devforum.zoom.us/t/example-of-react-with-hooks-integration-and-how-to-build-for-production/18936 "2020-05-25T05:22:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![miguel.villarreal](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/miguel.villarreal/32/2471_2.png) [@miguel.villarreal](https://devforum.zoom.us/u/miguel.villarreal)\
**Post date:** [May 25, 2020, 5:22am UTC](https://devforum.zoom.us/t/example-of-react-with-hooks-integration-and-how-to-build-for-production/18936/1 "2020-05-25T05:22:04Z")

</div>

**Description**  
More of a post than a question, but i have seen people having issues building for production, or using a implementation for react, so i made a snippet using react hooks

**Which version?**  
For React 16 and Web SDK 1.7.7

```
import React, { useState, useEffect } from "react";
import { ZoomMtg } from '@zoomus/websdk';
import axios from 'axios';
import 'jquery/src/jquery';

function Zoom({ meetingNumber, passWord, userName, role }) {

    const [zoomState, setZoomState] = useState({
        meetingNumber: '',
        passWord: '',
        userName: 'user',
        meetingLaunched: false,
        leaveUrl: "http://localhost:3000",
        role: 1
    })

    useEffect(() => {
        setZoomState({
            ...zoomState,
            meetingNumber: meetingNumber,
            passWord: passWord,
            userName: userName,
            role: role
        });
    }, [meetingNumber, passWord, userName]);

    useEffect(() => {
        console.log('load cannons')
        ZoomMtg.setZoomJSLib('https://source.zoom.us/1.7.7/lib', '/av');
        ZoomMtg.preLoadWasm();
        ZoomMtg.prepareJssdk();
    }, [])

    useEffect(() => {
        console.log(zoomState)
    }, [zoomState]);

    const updateField = e => {
        setZoomState({
            ...zoomState,
            [e.target.name]: e.target.value
        });
    };

    const getSignature = async (meetConfig, apiKey) => {

        await axios.post('signatureEndpointURL', {
            "meetingNumber": meetConfig.meetingNumber,
            "role": +meetConfig.role
        })
            .then(result => result.data)
            .then(response => {
                ZoomMtg.init({
                    leaveUrl: meetConfig.leaveUrl,
                    isSupportAV: true,
                    debug: true,
                    success: function () {
                        ZoomMtg.join({
                            signature: response.signature,
                            apiKey: apiKey,
                            meetingNumber: meetConfig.meetingNumber, // required
                            userName: meetConfig.userName, // required
                            passWord: meetConfig.passWord, // If required; set by host
                            success(success) {
                                console.log("join meeting success", success);
                            },
                            error(res) {
                                console.log(res);
                            }
                        });
                    },
                    error(res) {
                        console.log(res);
                    }
                });
            });
    }

    const launchMeeting = e => {
        const apiKey = "apiKey";

        const meetConfig = {
            meetingNumber: zoomState.meetingNumber,
            leaveUrl: zoomState.leaveUrl,
            userName: zoomState.userName,
            passWord: zoomState.passWord,
            role: zoomState.role
        };

        getSignature(meetConfig, apiKey)

        setZoomState({
            ...zoomState,
            role: 1,
            meetingLaunched: true
        });
    }

    return (
        <div className="App">
            {true ? (
                <nav className="app-nav">
                    <form className="form">
                        <label>
                            <span>MeetingID:</span>
                            <input
                                className="form__input"
                                type="text"
                                name="meetingNumber"
                                placeholder="Meeting #"
                                value={zoomState.meetingNumber}
                                onChange={updateField}
                            />
                        </label>
                        <label>
                            <span>Username:</span>
                            <input
                                className="form__input"
                                type="text"
                                name="userName"
                                placeholder="Username"
                                value={zoomState.userName}
                                onChange={updateField}
                            />
                        </label>
                        <label>
                            <span>Password:</span>
                            <input
                                className="form__input"
                                type="text"
                                name="passWord"
                                placeholder="Password"
                                value={zoomState.passWord}
                                onChange={updateField}
                            />
                        </label>
                        <label>
                            <span>Password:</span>
                            <input
                                className="form__input"
                                type="text"
                                name="role"
                                placeholder="role"
                                value={zoomState.role}
                                onChange={updateField}
                            />
                        </label>
                    </form>
                    <div className="button-wrap">
                        <button onClick={launchMeeting} className="button">Launch Meeting</button>
                    </div>
                </nav>
            ) : (
                    <div id="zmmtg-root"></div>
                )}
        </div>
    )
}

export default Zoom;

```

For production build, you can use the next npm module:

[react-app-rewired](https://github.com/timarney/react-app-rewired), which allows you to add a config overwrite file and modify Terserplugin, the main advice came from another zoom devforum user, so when i encounter his post, i will credit him as deserved, meanwhile this is how you use yarn build from a create-react-app and have it not affect zoom sdk while minifying the build.

this is the **config-overrides.js** snippet:

```
const TerserPlugin = require('terser-webpack-plugin');

module.exports = (config) => {

    if (!config.optimization) {

        config.optimization = {};

    }

    config.optimization = {

        minimizer: [

            new TerserPlugin({

                terserOptions: { keep_fnames: /./ } //this minifies the function names

            })

        ]

    }; return config;

}
```

---

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tommy/32/72769_2.png) [@tommy](https://devforum.zoom.us/u/tommy)\
**Post date:** [May 27, 2020, 10:53pm UTC](https://devforum.zoom.us/t/example-of-react-with-hooks-integration-and-how-to-build-for-production/18936/2 "2020-05-27T22:53:20Z")

</div>

Hey @miguel.villarreal,

Thanks for your contribution to the Zoom developer community! I am sure developers will find this helpful! 🙂

-Tommy

---

<div class="post-metadata">

**Author:** ![ronyfirst](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/ronyfirst/32/9748_2.png) [@ronyfirst](https://devforum.zoom.us/u/ronyfirst)\
**Post date:** [June 3, 2020, 3:12pm UTC](https://devforum.zoom.us/t/example-of-react-with-hooks-integration-and-how-to-build-for-production/18936/3 "2020-06-03T15:12:32Z")

</div>

Please help me t

“When I press screen window for sharing then there is a notification “screen sharing has failed to start” and Error code- 105035”

---

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tommy/32/72769_2.png) [@tommy](https://devforum.zoom.us/u/tommy)\
**Post date:** [June 8, 2020, 10:35pm UTC](https://devforum.zoom.us/t/example-of-react-with-hooks-integration-and-how-to-build-for-production/18936/4 "2020-06-08T22:35:47Z")

</div>

Hey @ronyfirst,

Please create a new thread here: #web-sdk

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![Sebastian](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/sebastian/32/10992_2.png) [@Sebastian](https://devforum.zoom.us/u/Sebastian)\
**Post date:** [June 24, 2020, 9:15pm UTC](https://devforum.zoom.us/t/example-of-react-with-hooks-integration-and-how-to-build-for-production/18936/5 "2020-06-24T21:15:03Z")

</div>

hey did you solved your problem?

---

<div class="post-metadata">

**Author:** ![tommy](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/tommy/32/72769_2.png) [@tommy](https://devforum.zoom.us/u/tommy)\
**Post date:** [June 25, 2020, 5:45pm UTC](https://devforum.zoom.us/t/example-of-react-with-hooks-integration-and-how-to-build-for-production/18936/6 "2020-06-25T17:45:37Z")

</div>

Hey @Sebastian,

Please create a new thread here: #web-sdk

Thanks,  
Tommy

---

<div class="post-metadata">

**Author:** ![DeveloperBot](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/developerbot/32/12632_2.png) [@DeveloperBot](https://devforum.zoom.us/u/DeveloperBot)\
**Post date:** [August 21, 2020, 10:26pm UTC](https://devforum.zoom.us/t/example-of-react-with-hooks-integration-and-how-to-build-for-production/18936/7 "2020-08-21T22:26:59Z")

</div>

Closed on August 21, 2020, 10:26pm UTC


