J
J
Jake_Hold2019-05-04 22:18:30
JavaScript
Jake_Hold, 2019-05-04 22:18:30

How to call an imported function in js?

It is necessary to transfer the function for the condition from the first js file to the second file.
The first theme.jsfile has the following code:

export let DarkTheme = () => {
  /*Переключение на темную тему*/
  $('#darkTheme').css({'display' : 'block'})
  $('#lightTheme').css({'display' : 'none'})
}

export let DarkTheme = () => {
  /*Переключение на светлую тему*/
  $('#darkTheme').css({'display' : 'none'})
  $('#lightTheme').css({'display' : 'block'})
}

In the second file header.js:
import {DarkTheme, LightTheme} from './theme'

if (window.location.pathname == '/' || window.location.pathname == '/list') {

  if (localStorage.getItem('themeStyle') === 'dark') {
      /*здесь по идее мне нужно вызвать функции с первого файла, чтобы проверить условие - какая сейчас выбрана тема*/ 
   }
   else {
     //
   }

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
andrei_pro, 2019-05-04
@andrei_pro

theme.js

function DarkTheme() {}
function LightTheme() {}

export {LightTheme, DarkTheme}

header.js
import {DarkTheme, LightTheme} from './theme'

LightTheme()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question