Y
Y
ymenaidtopa2021-08-08 21:17:06
JavaScript
ymenaidtopa, 2021-08-08 21:17:06

How to fix this error Vk mini apps ReactJS?

npm run deploy produces an error:

Failed to compile.

./src/App.js
  Line 46:3:  Parsing error: Unexpected token

  44 | <script>
  45 |   window.addEventListener('load', function() {
> 46 |   var user_id = returnStr;   // user's id
     |   ^
  47 |   var app_id = 7921483;  // your app's id
  48 |
  49 |     admanInit({

App.js itself:
import React, { useState, useEffect } from 'react';
import bridge from '@vkontakte/vk-bridge';
import View from '@vkontakte/vkui/dist/components/View/View';
import ScreenSpinner from '@vkontakte/vkui/dist/components/ScreenSpinner/ScreenSpinner';
import '@vkontakte/vkui/dist/vkui.css';

import Home from './panels/Home';
import Persik from './panels/Persik';

const App = () => {
  const [activePanel, setActivePanel] = useState('home');
  const [fetchedUser, setUser] = useState(null);
  const [popout, setPopout] = useState(<ScreenSpinner size='large' />);

  useEffect(() => {
    bridge.subscribe(({ detail: { type, data }}) => {
      if (type === 'VKWebAppUpdateConfig') {
        const schemeAttribute = document.createAttribute('scheme');
        schemeAttribute.value = data.scheme ? data.scheme : 'client_light';
        document.body.attributes.setNamedItem(schemeAttribute);
      }
    });
    async function fetchData() {
      const user = await bridge.send('VKWebAppGetUserInfo');
      setUser(user);
      setPopout(null);
    }
    fetchData();
  }, []);

  const go = e => {
    setActivePanel(e.currentTarget.dataset.to);
  };

      VK.api("users.get", {"v":"5.124"}, function (data) {
        var id = data["response"][0]["id"];
            returnStr = id;
    });

bridge.send("VKWebAppShowNativeAds", {ad_format:"preloader"});
<script type="text/javascript" src="//vk.com/js/api/xd_connection.js?2" charset="utf-8"></script>;
<script type="text/javascript" src="//ad.mail.ru/static/admanhtml/rbadman-html5.min.js" charset="utf-8"></script>;
<script type="text/javascript" src="//vk.com/js/api/adman_init.js" charset="utf-8"></script>;
<script>
  window.addEventListener('load', function() {
  var user_id = returnStr;   // user's id
  var app_id = 7921483;  // your app's id
 
    admanInit({
      user_id: user_id,
      app_id: 7921483,
      mobile: true,
      type: 'preloader' 			// 'preloader' or 'rewarded' (default - 'preloader')
      // params: {preview: 1}   // to verify the correct operation of advertising
    }, onAdsReady, onNoAds);
 
    function onAdsReady(adman) {
      adman.onStarted(function () {});
      adman.onCompleted(function() {});
      adman.onSkipped(function() {});      
      adman.onClicked(function() {}); 
      adman.start('preroll');
    };
    function onNoAds() {
    	console.log(`No ad`)
    };
  });
</script>
.then(data => console.log(data.result))
.catch(error => console.log(error));

  return (
    <View activePanel={activePanel} popout={popout}>
      <Home id='home' fetchedUser={fetchedUser} go={go} />
      <Persik id='persik' go={go} />
    </View>
  );
}

export default App;

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question