How to effectively manage multiple stylesheet links in React Native Expo development

Hello, my name is Antika. I recently embarked on a coding journey and have been focusing on learning HTML/CSS/JS along with the basics of React. As a beginner developer, my current project involves creating a Study planner app for myself using React Native Expo.

One challenge I am facing is transitioning from traditional programming languages like HTML, CSS, and JS to more advanced ones like React and Flutter. Specifically, I'm struggling with importing multiple stylesheets in React Native projects, similar to how it's done in HTML.

Below are the individual CSS files that I need to import:

    <link rel="stylesheet" href="assets/css/vendor/bootstrap.min.css">
    <link rel="stylesheet" href="assets/css/vendor/font-awesome.css">
    <link rel="stylesheet" href="assets/css/vendor/slick.css">
    <link rel="stylesheet" href="assets/css/vendor/slick-theme.css">
    <link rel="stylesheet" href="assets/css/vendor/base.css">
    <link rel="stylesheet" href="assets/css/plugins/plugins.css">
    <link rel="stylesheet" href="assets/css/style.css">

Currently, I am utilizing Expo for this specific project. Despite being new to React Native and Expo, I am determined to expand my knowledge and grasp different features and syntax. Any assistance or guidance provided would be greatly appreciated.

Answer №1

When working with styling in react native, it's important to consider it as a separate entity from traditional CSS. While the syntax may be somewhat similar, the values and usage differ.

In the example provided, all styles are imported globally, allowing any HTML element to utilize them.

In react, it is more common practice to only import the styles you need when you need them.

For instance, if I want to create a style that makes text appear red, I could define it in a separate file like this:

//myStyles.js
export const MyStyles = StyleSheet.create({
  redText: {
    color: 'red',
  },
});

Then, in any file where I want to use the redText style:

import {MyStyles} from "/path/to/myStyles"

//...other code
<Text style={MyStyles.redText}>this is red </Text>
//... other code

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

React's Conditional Rendering

Let's imagine having these initial conditions: this.state = {plans: [], phase: 'daybreak'} along with a dynamic JSON object fetched from an API containing various schedules that may change periodically, for example: plans = {"daybreak": " ...

React Native: Unable to update React state during logout process

Currently, I am working on a mobile app and learning new practices in React every day as a junior developer. Today, I need assistance with implementing a User Logout function. In my Profil.js file, I have the Logout function inside an IconButton that gets ...

In internet explorer with AJAX, the UI is refreshed by Javascript only when an alert() function is triggered

Having an issue in Internet Explorer, works perfectly in Firefox. There is a javascript function that updates the UI (screen content) before an AJAX call. However, it does not update the UI unless an alert box prompt is used. Without the alert box, the UI ...

The request to retrieve data from the model at http://localhost:9000/model/data.json resulted in a 404

This is the path to my directory I have a npm server running on http://localhost:9000/ to utilize the cytoscape module. However, my server is unable to locate my json file. What could be the issue with my code? This is the source code of my index.js file ...

Determining the identity of an HTML element using its surrounding values

I have a webpage with a table displaying various services and their corresponding download buttons. Here is an example of the content: nov. service 1 [ click to download pdf ] nov. service 5 [ click to download pdf ] nov. service 3 [ ...

Encountering an error when attempting to start npm after creating a react app

I've been attempting to create a new React app but I'm having trouble running `npm start`. I don't quite understand the error message, so I'm hoping someone can help. I also tried deploying on GitHub yesterday (if that information is he ...

Differences in background-size among various browsers

Having some trouble with scaling backgrounds on different browsers. Initially designed website on Google Chrome, but background doesn't scale properly when viewed on iPhone or older versions of IE. Started with: background-size: 100% 150%; Then c ...

How can I make sure that the combobox in my Ionic app is aligned with the text fields in a row?

From the image provided, it's evident that my HTML code looks like this: <ion-row> <ion-col> <ion-item> <searchable-ion-select isModal="true" name="country" valueField="code" [(ngModel)]="country" title="Country" ...

Preserving Search and Filter Settings in jQuery Data Tables

I've been working with a datatable and I'm trying to figure out how to keep dropdown filters and search parameters saved when the page is reloaded, just like shown in the screenshot below. However, I also want these parameters to be cleared if th ...

Fill in the username and password on the login page of the website when it is accessed through the mobile application

Currently, I have a Joomla website and mobile App that are hosted on different servers. Both are owned by the same party, and users have accounts on both platforms with identical ID's and passwords (even though they are stored in separate databases, w ...

My local requests are being blocked by both Chrome and Firefox

Recently, I've been experimenting with local flash development and trying to inject my swf file into a website served by my test server. To enable loading of local resources in Chrome, I set --disable-web-security. In FireFox, I made the following a ...

A guide on extracting the current website URL in a React application

I wanted to find a method to duplicate the text from a URL so that users could easily share the link with others. ...

What steps are needed to develop a proper HTML structure for this specific box in order to achieve the desired aesthetics?

Currently working on a box that includes various tags and an input field for adding new tags. The goal is to make this box resemble the tag form used on YouTube: https://i.stack.imgur.com/RSj2p.png This particular layout features a box with existing tags ...

Top method for verifying input during keyup or blur events

When it comes to validating user inputs, I often find myself wondering about the best approach to take. In this case, I have created a regex for numbers with decimal points. .ts part checkIsNumber(event) { console.log('event', event.target. ...

How can you convert all nodes of a nested JSON tree into class instances in Angular 2 using Typescript?

I have a Leaf class that I want to use to convert all nodes in a JSON response into instances of Leaf. The structure of the JSON response is as follows: JSON Response { "name":"animal", "state":false, "children":[ { "name" ...

The CSS overflow scroller trims the excess background color

Attempting to build a website, I encountered an issue with displaying a scroll bar. Despite using the CSS property overflow: auto, I faced another problem. Let me illustrate the issue through a simple example. I have an outer div with the style overflow: ...

Uploaded images from mobile devices appear to be rotated when viewed on desktop browsers like Chrome and Firefox

I'm facing a strange issue where an image uploaded from a mobile device to my website appears rotated on Chrome and Firefox when viewed on a desktop. However, it displays correctly on mobile browsers like Chrome Mobile and Safari Mobile. It seems tha ...

Expanding the functionality of the Ember JSONAPIAdapter for retrieving JSON data from a specified URL

As a newcomer to Ember.js, I am currently delving into understanding how Ember works. One issue I have encountered is calling my Django API from an Ember.js route using the following code: this.store.findAll('MYMODEL', 'ANOTHER_MODEL_ID&apos ...

Creating models or bulk creating promises in a seed file

When working with a promise chain to add data in JavaScript, I usually start by using Node.js or another method and it works fine (with some variations). However, when attempting to implement this promise chain in a sequelize seed file with the sequelize- ...

Browse through different states by clicking on the <a> </a> tag

Is there a way to switch between states defined by $stateProvider when clicking on the <a> </a> tag? Below are the states I have set up: $stateProvider //region page States .state('page1', { url: "/pg1", ...