#What do these symbols mean

25 messages · Page 1 of 1 (latest)

fair quail
#

<a style={{ backgroundImage: `url(${(`../assets/images/${posts.image}`)})`}} >

Hi, can someone help me understand what exactly is happening here? Theres way too many symbols here and im lost. What does the first {} do, what the second, why is there a $, why ``. Is there a less confusing way of writing this?

Also i have a thing called posts.style, which is defined like so:

const trendingConfig = {
    1:{
        gridArea: '1 / 2 / 3 / 3'
    }
}

const mergeStyles = (posts: any, config: any): void => {
    posts.forEach((post, index: number) =>{
        // TODO? if (index)
        post.style = config[index];
    })
}

and i wanna add it together with the preexisting code i showed in the beginning, how do i do that?

worn spear
#

/run

const a = 'hello';
const b = 'world';
console.log(`${a}, ${b}`);
bronze quarryBOT
#

Here is your js(18.15.0) output @worn spear

hello, world
worn spear
#

The ${} allows you to put variable inside of a string.

#

And that can only happen inside of backticks

#
  <a style={{ backgroundImage: 'url(`../assets/images/${posts.image}`)'}} > 

This might be a easier way to write it? Otherwise you could try building the URL elsewhere and passing the entire thing in.

fair quail
#

i see , thanks

#

do you know also what is the differance between having all of that within {} and withing {{}}, i noticed {{}} has access to some variables, and {} to others, according to my IDE

fair quail
#

TSX, but yeah its react

worn spear
#

You are basically just passing in an object. And the outer curly brace is JSX syntax

lost swan
worn spear
fair quail
#

Thanks 🙂

fair quail
#

In the second code i sent, am i adding gridArea: '1 / 2 / 3 / 3' to all of the posts or just the one in the 1st position? Do i need to so an if statement to make sure it only applies to the one in array position 1? Also how do i add that together to the background image style (the first code)

#

posts is a object (i think) with 5 units

worn spear
#

And position one = second element

fair quail
#

so whats happening is all elements exept 1 are null so it sets post.style to null except for the position 1 one?

#

post.style = config[index];

#

thats what this line does?

worn spear
#

I think it would be undefined rather than null

#

But otherwise yes