#styled components

1 messages Β· Page 1 of 1 (latest)

woeful wind
#

I'm watching styled components course and in the example here we trying to reverse the text inside a button but how this works without using the join() method after the reverse() method ?

random cloak
#

You should be able to do it with css only:

  unicode-bidi:bidi-override;
  direction:rtl;
#

You just need to setup your styled component to apply the css conditionally based on a prop

woeful wind
random cloak
#

Oh sorry I misunderstood your question haha The reason why it works is because you pass on a string, which you split then reverse. The end result is a reversed array which you obviously know.

When you pass in an array of primitive values in our case an array of string, react will make text nodes out of each member and render it to the DOM

random cloak
#

Now the problem with this approach , that the children element can be string, array, jsx element (object defined in a particular way) etc... So this approach would only work with strings.

You could follow an approach where you "clone" the react child elements and check their type and you only perform the splitting and reversing when it is a string.

React gives is utility functions to do that, if you are interested I could make you a demo.

woeful wind
#

Thanks and no need for demo i get you πŸ’œ

random cloak
woeful wind
#

just so you can get the scrimba hoodie πŸ˜‰

random cloak
#

I didn't even know you can use these points until 6-8 months haha

#

it was a nice surprise

woeful wind
#

it seems like you helped a lot of people πŸ˜‚

random cloak
woeful wind
#

actually yeah that is true when you explain something to some you understand it better

random cloak
woeful wind
#

true

#

so where are you from ?

random cloak
#

I'm from Hungary, what about you?

woeful wind
#

Egypt

#

my brother lives in Graz , I think it should be somewhere near you

#

but not like near you

random cloak
random cloak
random cloak
woeful wind
#

oh so you live now in Uk

random cloak