** when I start the software for the first time the "items" state property is not set. Not even in setItems.
If I try to reload a second time instead it is valued. How can I change the following code to make the status value also on first opening?**
(https://i.stack.imgur.com/8bgSP.png)](https://i.stack.imgur.com/8bgSP.png)
How can I change the following code to make the status value also on first opening?
enter code hereI am still learning React Hooks, but I think I see the issue. In your useEffect function, you populate items by calling the _getItemButton function, but then you immediately setItems back to an empty array. Remove the setItems([]); statement in the useEffect function and see if that fixes the issue.
By including the empty array, the useEffect function only runs the first time. Clicking the button runs the _getItemButton function again directly, not using the useEffect function, so that is why it works the second time.
Hope this helps!
Related
Still I’m confused on that tkcalendar virtual events usage to bind user actions on the calendar days selections. Making something like follow,
calendar.bind("<<CalendarSelected>>", print(calendar.get_date())
That print the default date once the I run the script but when I select on the displayed calendar nothing is printed. Normally any selection on any day on the calendar should be printed if was really bound. I did something wrong right ?
You need to use a lambda function instead
calendar.bind("<<CalendarSelected>>", lambda: print(calendar.get_date())
You code will currently bind the result of the print function as the callback for the bind. Since print returns None, no function will be called.
A lambda creates an anonymous function.
If your code gets more complex than a single line, put this code in to a function of its own and use the name of that function in the bind method, for example
calendar.bind("<<CalendarSelected>>", showDateToUser)
I have the following function to bind my dynamically generated Actions in the ToolBar with a name passing function:
def bind_action(self, action, name):
'''bind an Action to the ToolBar'''
action.triggered.connect(lambda: self._fct.get_name(name))
Now the user may change the name at runtime. And I call the function a second time to bind the new name. If the QAction is triggered now, I have the problem that both triggers are sent. Is it possible to delete the first connect again? I found a workaround (I check if the name is in a list), but I want to have it neater.
As private feedback I got this question recommended: stackoverflow.com/questions/45090982/… It is the exactly opposite problem. There, a user want to know how he can add a second parameter, my Question is: How can I get rid of the first triggered.connect()?
Short 10sec video of what is happening: https://drive.google.com/file/d/1YZccegry36sZIPxTawGjaQ4Sexw5zGpZ/view
I have a CLI app that asks a user for a selection, then returns a response from a mysql database. The CLI app is run in node.js and prompts questions with Inquirer.
However, after returning the table of information, the next prompt overwrites the table data, making it mostly unreadable. It should appear on its own lines beneath the rest of the data, not overlap. The functions that gather and return the data are asynchronous (they must be in order to loop), but I have tried it with just a short list of standard synchronous functions for testing purposes, and the same problem exists. I have tried it with and without console.table, and the prompt still overwrites the response, as a console table or object list.
I have enabled checkwinsize in Bash with
shopt -s checkwinsize
And it still persists.
Is it Bash? Is it a problem with Inquirer?
I was having this issue as well. In my .then method of my prompt I was using switch and case to determine what to console log depending on the users selection. Then at the bottom I had an if statement checking to if they selected 'Finish' if they didn't I called the prompt function again, which I named 'questionUser'.
That's where I was having the issue, calling questionUser again was overriding my console logs.
What I did was I wrapped the questionUser call in a setTimeout like this:
if(data.option !== 'Finish'){
setTimeout(() => {
questionUser();
}, 1000);
}
This worked for me and allowed my console log data to not get deleted.
Hopefully if anyone else is having this issue this helps, I couldn't find an answer to this specific question anywhere.
Is there a way in nightwatch to check whether a popup window appears after each click event?
I have a problem that randomly an error message appear and I don't want to write for each click event the same callback function.
I have already tried out the after and afterEach commands in the Global.js but then the commands will only run after the whole test suite.
I also have tried it local within a test file, although it also does not cover all single click events, even though the official website writes "... while beforeEach and afterEach are ran before and after each testcase (test step)"?
Solution I'm looking for:
.waitForElementVisible('selector')
.click('selector')
.click('selector')
Solution I have come up with so far:
.waitForElementVisible('selector')
.click('selector', isPresent)
.click('selector', isPresent)
isPresent as a callback function, which does the checking and close the popup window if it appears.
Is there another way to write a function (with or without after and/or forEach), so that it will be called after each click event or after each command. Thus, I don't have to write the isPresent repetitive code?
You can insert something like this in your page object file:
var popupCommand = {
popupCheck:function(){
return this.waitForElementVisible('selector', 5000)
.click('selector', isPresent)
.click('selector', isPresent)
},
module.exports = {
commands:[popupCommand],
elements:{
firstElement: {selector: 'xpath',locateStrategy: 'xpath'},
secondElement: {selector: 'css'},
}
}
Where 'popupCommand' will be the name of your page object file, for example 'Popup'. And also you will have to insert your isPresent callback function here so you can use it.
I did my best to explain you as much as possible what and how to do that :)
you should yse .switchWindow() method.
Why don't you write your own custom command specific for that case, so that way you will avoid repetitive code?
I was automating the an application (using Protractor) and I have come across situation where I wanted to select the an option from the type ahead using the DOWN arrow button from the Keyboard. Here is how I am approaching to this action.
After typing part into the text field I am getting the reference of each option that appear in the type ahead.
Now, I am using .each() method of protractor to iterate through each of the option to look for the required option.
I'm making the script to hit DOWN arrow button to iterate through each option in the type ahead.
Suppose there are 10 options displayed in the type ahead and the option that I need to select is at 5th position. Now when I reach the 5th position I am selecting the option but each() function still continues.
I want the loop to terminate when required option is selected. Something like BREAK statement in FOR loops.
BTW I have tried the above scenario with FOR loop but unable to use BREAK statement within then() handler.
Please let me know how to cope up with this situation.
You could throw an exception to terminate the loop. Put the loop inside try and use catch to wrangle your results. You can also just use a boolean variable to indicate that you have found a match and ignore everything after that point. I would just use a for loop though.
Edit:
You could add a variable to hold an action before the allBenchmarks.each
var action
Then inside the test
if(dataValue == optionToSelect){
action = function() {benchmark.click(); ...}
}
After the loop exits call the action
if (action) action()