0

I need to import multiple css files conditionally in react native project like

import React, { Component } from "react";
if(this.state.language = "he"){
  import styles from "./he";
}else{
  import styles from "./en";
}

But it's not working. I need to add 2 different CSS for LTR and RTL based on language.

1
  • Welcome to stackoverflow! Can you explain what is wrong? (Share un-/expected behavior or an error.) Commented Jul 16, 2019 at 11:10

1 Answer 1

1

You can do like the following code

import heStyles from "./he";
import enStyles from "./en";

const styles = this.state.language = "he" ? heStyles : enStyles;
Sign up to request clarification or add additional context in comments.

11 Comments

can I get this.state.language before import statement ?
state belongs to your class component, you cant get it before import
if you store language in asyncstorage, you could create separate style file, import those style file then export specic style based on language get from asyncstorage
I can put that asyncstorage condition here as well right?
is there any example available for export specific style based on language get from asyncstorage
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.