"Expected an assignment or function call and instead saw an expression no-unused-expressions" "while using Optional Chaining" - use-effect

useEffect(()=>{
scrollRef.current?.scrollIntoView({behavior:"smooth"})
},[messages])
This use hook shows an error while compiling as "Expected an assignment or function call and instead saw an expression no-unused-expressions", the "?" used is -i think- is the cause which is called "Optional chaining" ..Right? im not sure.
I couldnt understand what makes this statement doesnt work for me , please help me. every info you pass would be be really greatfull.
is it beacuse i miss any npm module?..

Related

Discord.js message includes

Hi im currently adding some new features to a bot and it's been going great with some amazing progressions each day. I ran into an issue that i can't seem to solve even though i feel like the solution is right in front of me. In my code i have an if statement to check if a user has more matches won than 22 in the database, if so they are allowed to equip a certain background if not it returns an error message. I tried to do another if statement to check if a certain user is trying to run the command by matching their discord ID and for some reason it runs both the if statements when doing either command even though i used message.content.includes to specify what arguments it should look for in the command. Any help would be appreciated
According to the mozilla docs:
The comma operator (,) evaluates each of its operands (from left to right) and returns the value of the last operand.
This means that only the second operand in each if statement is being returned, ignoring message.content.includes().
Changing the , to && should fix the issue.
source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator

Property assignment expected. This expression is not callable. Type {} has no call signatures. (how to solve this?)

I wanted to update a badge count in a chat room using cloud function trigger which is a nested map.
I'm updating badges in the frontend without any issue but I want the create a cloud function for this to reduce frontend workloads.
but when I tried to pass a dynamic variable as field/key, the compiler is not happy and it's giving me an error.
the expected output should be like this
Backtick doesn't work so I tried to change the backtick to double quote to be able to compile, but this was the output which is not what i want.
anyone knows how to make this work? please help.
its syntax issue, missing [ & ].
it should be { [`badgeCount.${receveid}`]: fire.....

Added an extra variable to a VBA function - now has compile error stating Expected:=

I have a VBA function that worked fine, until I tried to pass an extra variable to it. Now the code won't run, and I get an error stating Expected:=, I've tried renaming the function, but no help.
Was - Function GetData(site_add)
Changed to Function GetData(site_add, temporary) and failed - despite changing the call to the function accordingly...!?!
Is it possible that the compiler is glitching and I should focus on that? I have other functions in the code that use 5 call 5 variables and don't even call/use them all...!? Help...
By adding the second parameter, you are effectively telling the compiler that every call to this method now requires two parameters instead of one. So you have to find everywhere you call the GetData() function and make sure it now passes two parameters instead of one, even if the second parameter is Nothing. Now, if you want it to default to nothing so you don't need to pass it you can rewrite it as
GetData(site_add, Optional temporary)
*my vb is rusty, so take my example with a grain of salt please.

Shoulda context and syntax, ruby 2.1

The following code doesn't compile in ruby 2.1 on OS X. The error message is quite strange:
/Library/Ruby/Gems/2.0.0/gems/rake-10.3.2/lib/rake/rake_test_loader.rb:10:in `require':
/Users/jayunit100/Development/leitmotif/test/test_leitmotif.rb:21:
syntax error, unexpected keyword_end, expecting end-of-input (SyntaxError)
That is, it is requesting that i remove the final "end" statement from the class, and when i do so, it indeed compiles ! So my first question is , how or why it is that the rake_test_loader wants a class declaration without a closing end block.
require 'helper'
require 'minitest/autorun'
class TestLeitmotif < MiniTest::Test
### A simple test
context "Leitmotif core tests" do
setup do
#lm = Leitmotif.new
end
should "run should return 1 if arguments are invalid"
#lm=Leitmotif.new
print("\nASDF\n")
print(#lz.inspect);
print(#lm.inspect)
print("\nASDF\n")
x=#lm.run("","")
#assert_equal 1, x
end
end
end
My second problem here is that the variable
#lm = Leimotif.new
Which is declared in the setup block, seems to be inaccessible in the should method.
My suspicion here is that somehow the syntax of the should framework is not parsed correctly in the current version of ruby, but am quite new to ruby so any insight would be appreciated.
Thanks!
This error is because you are missing the do at the beginning of the block passed to should.
should "run should return 1 if arguments are invalid" do
#lm=Leitmotif.new
print("\nASDF\n")
print(#lz.inspect);
print(#lm.inspect)
print("\nASDF\n")
x=#lm.run("","")
#assert_equal 1, x
end
Most implementations of shoulda on Minitest simply alias the Minitest Spec DSL's it to should, so those docs should help.

Pass by reference problem with PHP 5.3.1 [duplicate]

This question already has answers here:
mysqli bind_param() expected to be a reference, value given
(3 answers)
Closed 12 months ago.
Ok, this is a weird problem, so please bear with me as I explain.
We upgraded our dev servers from PHP 5.2.5 to 5.3.1.
Loading up our code after the switch, we start getting errors like:
Warning: Parameter 2 to mysqli_stmt::bind_param() expected to be a reference, value given in /home/spot/trunk/system/core/Database.class.php on line 105
the line mentioned (105) is as follows:
call_user_func_array(Array($stmt, 'bind_param'), $passArray);
we changed the line to the following:
call_user_func_array(Array($stmt, 'bind_param'), &$passArray);
at this point (because allow_call_time_pass_reference) is turned off, php throws this:
Deprecated: Call-time pass-by-reference has been deprecated in /home/spot/trunk/system/core/Database.class.php on line 105
After trying to fix this for some time, I broke down and set allow_call_time_pass_reference to on.
That got rid of the Deprecated warning, but now the Warning: Parameter 2 to mysqli_stmt::bind_param() expected to be a reference warning is throwing every time, with or without the referencing.
I have zero clue how to fix this. If the target method was my own, I would just reference the incoming vars in the func declaration, but it's a (relatively) native method (mysqli).
Has anyone experienced this? How can I get around it?
Thank you.
I just experienced this same problem, calling bind_param via call_user_func_array and passing an array of parameters. The solution is to modify the values in the array to be referenced. It's not elegant but it works.
call_user_func_array(array($stmt, 'bind_param'), makeValuesReferenced($passArray));
function makeValuesReferenced($arr){
$refs = array();
foreach($arr as $key => $value)
$refs[$key] = &$arr[$key];
return $refs;
}
You are passing an array of elements ($passArray). The second item inside the passed array needs to be a reference, since that is really the list of items you are passing to the function.
Actually, be aware that there is a bug with PHP 5.3.1 concerning references and all call family of functions:
PHP Bugs #50394: Reference argument converted to value in __call
The behavior you are seeing might be a result of this bug and any attempt to fix it code wise may cause problems in the long run.
The problem has been fixed in the SVN version of PHP. Until 5.3.2 is released, you may compile a new version for use, or downgrade to an earlier version.
We were experiencing this same problem with this code:
call_user_func(array($strCartHandler, 'CartPurchaseEvent'), $strCartEvent, $objToUser, null, $this);
My solution was to just skip call_user_func altogether and do this:
$strCartHandler::CartPurchaseEvent($strCartEvent, $objToUser, null, $this);
I think what is deprecated is passing a reference through a function. In the function definition you do something like:
function(&$arg) {
}
This doesn't help you much but you probably need not pass the reference anyway. I guess you could try a wrapper function.
function wrapper($stmt, &$passArray) {
call_user_func_array($stmt, $passArray);
}
I think the mysqli_bind_param() and mysqli_bind_result() functions are very awkward to use. I've encountered the same difficulty as you describe using them in combination with call_user_func_array()
My workaround was to stop using mysqli and instead use PDO_mysql. It has a much easier usage:
$pdoStmt->execute( $passArray );
This will helps:
<?php
call_user_func_array(Array($stmt, 'bind_param'), array(&$passArray));
function bind_param ($val)
{
$val = (is_array($val)) ? $val[0] : $val;
// operations...
}
?>
The second paramer Must be an array. apparently this was only enforced in 5.3
I've got a similar problem, the current code didnt work:
$query="Select id,name FROM mytable LIMIT ?,?";
$params=Array('ii');
array_push($params,$from_var);
array_push($params,$to_var);
...
$stmt=$link->prepare("$query");
$ref=new ReflectionClass('mysqli_stmt');
$method=$ref->getMethod("bind_param");
$method->invokeArgs($stmt,$params);
...
It told that "Parameter 2 to mysqli_stmt::bind_param() expected to be a reference, value given"
And then, in despair, I've tried to take $from_var and $to_var in quotes. And it worked!
$params=Array('ii');
array_push($params,"$from_var");
array_push($params,"$to_var");
Hope, it will help somebody, good luck :)

Resources