How to import context from a file which is 2-steps up

Viewed 40

This is my folder hierarchy-

SRC -

/assets
/components
App.jsx

COMPONENTS -

/screens/Login.jsx
Carousel.jsx
Navbar.jsx

Suppose I am in the Login.jsx file. From there how will I import a context which was declared in App.jsx

When I start writing this code -

import React from 'react';
import { IsLoggedInContext } from '../'

The autocompletes in vscode editor I get are -

  • Carousel
  • Navbar
  • Screens

When I start using .../ no autocomplete comes for the App file and it doesn't also work if I manually write this code -

import { isLoggedInContext } from '.../App'

So, how will I import the context in the Login.jsx file? Is there any way?

1 Answers

A single . is the current directory, a double .. is the parent directory. A triple ... isn't valid syntax for referencing directory/file structures.

From src/components/screens, ".." gets you into src/components, and "../.." gets you up another level back to src.

import { isLoggedInContext } from '../../App';
Related