This question already has answers here:
Backticks (`…`) calling a function in JavaScript
(3 answers)
Closed 5 years ago.
I'm following a React course and came across this lesson where they import a component from styled-components but what is strange to me is line 4 where they use the backticks interpolation without enclosing it in parenthesis and it seems it should not be any space between the backticks and the styled.header.
That's call Tagged Template Literals, a new feature in ES6.
You can read more about this in the styled-components docs and this article.
Related
This question already has an answer here:
Conditionally set background color in React component with Tailwind CSS
(1 answer)
Closed 3 months ago.
Tailwind states that the following is possible when it comes to arbitrary colors we don't want to pollute the tailwind config with:
bg-[#e73d3dFF]
Now in the code, when writting said color like this, it works:
bg-[#e73d3dFF]
Here is the part that is baffling me, when written using any form of compilation (I'll show all examples), it does not work. The string is printed out onto the HTML correctly, but the color isn't rendered.
Example 1
`bg-[${navItem.bg.hex}]`
Example 2
const classStyle = `bg-[${navItem.bg.hex}]`;
classNames({[classStyle]: true});
Example 3:
'bg-[' + {navItem.bg.hex} + ']';
All the examples above result in the HTML being printed correctly, so we do see:
<li class="bg-[#e73d3dFF]">
But, here's the kicker, the color isn't shown, the rules aren't applied, it's like the color rule wasn't created by Tailwind.
Any ideas?
Unfortunately, you can't use template literal strings to build tailwind classes.
They warn about that in their docs, too: https://tailwindcss.com/docs/content-configuration#dynamic-class-names
This question already has answers here:
React useEffect() : Most efficient way to compare if two arrays of objects are equal
(3 answers)
Closed 8 months ago.
Probably a basic question, but I have doubts on how works a useEffect with more than one element in the array. Given:
useEffect(()=>{alert("hi");},[one,two]);
Does the alert appear when one and two matches like if it was one && two or is it an or condition like "one || two"?
Also, is it possible to use comparison as well in the array like
useEffect(()=>{alert("hi");},[one===true,two===false]); ?
See the documentation:
The default behavior for effects is to fire the effect after every completed render. That way an effect is always recreated if one of its dependencies changes.
This question already has answers here:
Javascript appending object doesn't guarantee order
(3 answers)
Is the underscore prefix for property and method names merely a convention?
(6 answers)
Closed 3 years ago.
I'm using redux and a piece of my state has this structure:
{cityId: {name:cityName, population: numberOfPeople}}
something like:
{
1324:{name:"Clagary", population:1234, id: 1324},
46283: {name:"Edmonton", population: 5678, id: 46283}
}
Everything was fine till i needed to show them in a list with the same order that they have on the main object. At this point, I figured out that objects will auto-sort the keys if they are numbers. I tried to change them to string by putting them inside a "" but it didn't work ({"1324":{...}}).
So i tried adding and underline character as:
({"_1324":{...}})
Now it's working but I just have to double-check with some of you experts here to make sure that this is a good practice and it's normal to do it this way or if there is any better way to deal with numbers as keys in an object when the order matters.
So I'm asking react/redux experts to see if they would move to other solutions when they need the order or would just do what i did.
P.S. I really don't want to go back to use an array as this type of object store is much easier and handy for us in many ways.
This question already has answers here:
Naming Image using index of for loop in each iteration
(2 answers)
Closed 7 years ago.
I want to do this with a shorter operation. How can i do it? Thank you
data = [Test1;Test2;Test3;Test4;Test5;Test6;Test7;---- until-----;Test36];
You can solve this using eval, however the use of this function is usually not recommended:
eval(['data=[', sprintf('Test%d;',(1:36)),'];'])
Rather follow Dan's comment and don't create seperate matrices.
You can use the eval command to do this:
Test1=magic(5);
Test2=magic(5);
data=cell.empty(2,0);
for ii=1:2
data{ii} = eval(sprintf('Test%d', ii));
end
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
AuthComponent: Difference between allowedActions and allow()?
What is the difference between using the method
$this->Auth->allow()
and setting the variable
$this->Auth->allowedActions ?
I can't find any information about setting the allowedActions array where I expected to find it (http://book.cakephp.org/view/1251/Setting-Auth-Component-Variables) - but it exists in the API at http://api13.cakephp.org/class/auth-component.
Can someone please explain which different circumstances I should use them?
See this AuthComponent: Difference between allowedActions and allow()?