Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use colors object inside EStyleSheet.create #173

Open
NeRo8 opened this issue Aug 4, 2022 · 0 comments
Open

Use colors object inside EStyleSheet.create #173

NeRo8 opened this issue Aug 4, 2022 · 0 comments

Comments

@NeRo8
Copy link

NeRo8 commented Aug 4, 2022

I have dumb component, and for getting access to colors I must use EStyleSheet.value.

const DumbComponent = () => {
  const [isActive, setActive] = useState(false);

  //Current realisation
  const activeBackground = EStyleSheet.value('$red');
  const disabledBackground = EStyleSheet.value('$blue');

  return (
    <BumbElement color={isActive ? activeBackground : disabledBackground} />
  );
};

But can we put inside EStyleSheet.create custom object with colors what we need, and after use it in our component?

const styles = EStyleSheet.create({
  colors: {
    red: '$red',
    blue: '$blue',
  },
  contentContainerStyle: {
    flexDirection:'row'
  }
});

const DumbComponent = () => {
  const [isActive, setActive] = useState(false);

  return <BumbElement color={styles.colors[isActive ? 'red' : 'blue']} />;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant