How to prevent double data fetching, interferes when rendering html to an element
const _d = document; const buttonMore = _d.getElementById('myButton') let num = 0; async function main() { const response = await fetch(`http://127.0.0.1:8000/api/v1/?page=${num}`) const jsonData = await response.json() console.log(jsonData) const mapData = await jsonData.data.map((i) => { return `<h3>${i.attributes.title}</h3>` }) // check for data counts if (jsonData.data.length < 10) buttonMore.style.display = "none" _d.getElementById('root').insertAdjacentHTML('beforeend', mapData.join('')) } buttonMore.addEventListener('click', (e) => { num++ return main(); }) interferes with the fact that by clicking, it is rendered twice, that is, it repeats the same elements twice
webpack.config.js
const webpack = require('webpack'); const path = require('path'); const HtmlPlugin = require('html-webpack-plugin'); module.exports = { entry: ['@babel/polyfill', './index.js'], output: { path: path.resolve(__dirname, 'dist'), filename: 'bundle.js' }, plugins: [ new HtmlPlugin({ hash: true, template: './src/index.html' }) ], module: { rules: [ { test: /\.m?js$/, exclude: /(node_modules|bower_components)/, use: { loader: 'babel-loader', options: { presets: ['@babel/preset-env'] } } } ] }, devServer: { contentBase: path.join(__dirname, 'dist'), compress: true, port: 9000 } 

console.log(jsonData)duplicate data, or as page-by-page? - Rustam Gimranovreturnfrom the line whereinsertAdjacentHTMLexactly needs to be removed. And attach a picture that displays in the console once. - Rustam Gimranovmainfunction two times. If this happens without a webpack, it means that the webpack does not correctly assemble the bundle. - Stepan Kasyanenko