Automatic import/export of React components [duplicate] - javascript

This question already has answers here:
Is it possible to import modules from all files in a directory, using a wildcard?
(14 answers)
Closed 22 days ago.
I have a "Components" component and a "components" folder.
I want all the components in the folder to be automatically imported into "Components" for reuse. "Components.Button"
It's real?

I found the answer. This can't be done by default, but there is a good npm package for babel https://www.npmjs.com/package/babel-plugin-wildcard

Related

Creating app folder but getting TypeScript files instead of JavaScript [duplicate]

This question already has an answer here:
How to install Next.js Tailwind explicitly with .js?
(1 answer)
Closed 10 months ago.
I was following a tutorial, to set up and create an react.js + tailwindcss app, I (and the tutorial maker) used.
npx create-next-app -e with-tailwindcss [app name]
the files and all are created but instead of getting javascript files (index.js etc) I get it in typescript (index.tsx).
(his)
(mine)
I read the next.js documentation and it said that if I wanted a TypeScript file I should add the --TypeScript flag to the command, which I didn't, yet still got the TypeScript files.
I followed the video and I didn't make anything different from his, so I'm wondering what did I make wrong and how to fix it.
Sorry for using any wrong tags I really don't know what I should've used.
You did nothing wrong. The example with-tailwindcss was recently converted to TypeScript. You can read about the decision in the corresponding pull request

How do I use the style.css file in angular? [duplicate]

This question already has answers here:
angular-cli how to add global styles?
(14 answers)
Closed 11 months ago.
I wanted this file to be the global styling sheet. But I don't know how to make a component reference it. Angular set-up here
Here is my component:
You can easily create components using angular cli, run the below command in the terminal where your project is located.
Command : ng generate component component_name
You can also check out this link
angular-cli how to add global styles?

Nextjs components can't access env.local variables [duplicate]

This question already has answers here:
NextJS environment variables aren't working
(2 answers)
Closed 1 year ago.
I'm building a movie recommendation app and I'm trying to fetch over an Url that is defined on my .env.local file, however it seems that none of my components can access environment variables, but index.js and _app.js can. Is there any solution?
Edit: I don't know if this matters, but both my "pages" and "components" directories are on the same folder alongside the .env.local file.
You must use the prefix NEXT_PUBLIC_ if you want to access env variables from the client. Please checkout the documentation for more info: https://nextjs.org/docs/basic-features/environment-variables#exposing-environment-variables-to-the-browser

How to make core client-side JS functions availabe in TS [duplicate]

This question already has answers here:
Typescript cannot find name window or document
(3 answers)
Closed 2 years ago.
I have a TS project that uses Node, express, and handlebars. I also have some client-side JS that it uses with no problem. (Clarification: not using react, angular, vue, or any other client-side framework at the moment.)
I was looking into moving the client-side JS into TS as well. My Hello World example tries to use alert (literally alert("Hello World");) but won't compile (error: error TS2304: Cannot find name 'alert'.). Should be a simple enough, I just need to discover the module to import into the file (or the dependency to add to my package.config) to make core client-side JavaScript function available.
I can't seem to find the reference for how to do this (outside of a wealth of library-specific examples in angular, react, etc.).
So what dependency and/or import am I looking for to expose core client-side JS functions and the like to my TS project?
Ah.
The "lib" property of my tsconfig only included es2017. Added DOM and that fixed it.

Is it possible to import js file to another js file, just like in sass [duplicate]

This question already has answers here:
How do I include a JavaScript file in another JavaScript file?
(70 answers)
Closed 5 years ago.
Is it possible to import a javascript file to another javascript file, just like we import sass files?
This question might have been masked as a duplicate to some other question. But it is not because I know that we can concat two or more JavaScript files.
But I looking for a better. I like the idea of importing files in sass (I am looking for the same process, in JavaScript).
As it will also help to send only 1 request to the server.
You can use require.js or node export and import syntax. But you'll have to write ES6 JavaScript Code which is the next version to support import and export statements. Using a transpiler such as babel you can compile those ES6 code to ES5 which browser understands.
Read more about ES6 module system and babel here.
https://babeljs.io/learn-es2015/#ecmascript-2015-features-modules

Categories