Tuesday, 1 December 2020

navigator.share opens a smaller menu

I am using web share API. This is the code

navigator
  .share({
    title: document.title,
    text,
  })

When I click the button and the above code is called, the smaller menu for sharing is opened, but I want the other complete menu to be opened. Currently, the bigger one is opened by manually clicking more button in the smaller menu which is at the last of the list

The smaller one-

smaller smaller2

The bigger one

complete menu



from navigator.share opens a smaller menu

Cannot update a component while rendering a different component when using QueryRender and React context

I am having an issues I can't seem to work out. When I use the QueryRenderer HOC component from relay and render it as children via a react context I get the following error:

Cannot update a component (`Customers`) while rendering a different component (`Search `). To locate the bad setState() call inside `Search`, follow the stack trace as described in https://reactjs.org/link/setstate-in-render

My context and component are very simple. As soon as I replace the QueryRenderer the problem goes away, so I am 100% certain this HOC component is causing the issue.

//context
const SearchProvider = ({ getVariables, query, children }) => {
  const [searchTerm, setSearchTerm] = useState()
  return (
    <SearchContext.Provider value=>
      <Search getVariables={getVariables} query={query}>
        {children}
      </Search>
    </SearchContext.Provider>
  )
}
//component causing the error
const Search = ({ getVariables, query, setRetry, children }) => {
  const { searchTerm } = useSearch()
  return (
    <QueryRenderer
      environment={environment}
      query={query}
      variables=
      render={({ error, props, retry }) => children({ error, props, retry })}
    />
  )
}
//and for context the component that is rendering the SearchProvider component
const Customers = () => {
  const getVariables = searchTerm => {
    //work out and return variables
  }
  return (
    <>
      <h1 className="text-xl mb-2">Customers</h1>
      <SearchProvider query={query} getVariables={getVariables}>
        {({ error, props }) => {
          if (error) return <Error />
          if (!props) return <Loading />
          return (
            <ul className="flex flex-wrap w-full mt-4">
              {props.users_connection.edges.map(({ node }) => (
                <Customer key={node.userId} customer={node} />
              ))}
            </ul>
          )
        }}
      </SearchProvider >
    </>
  )
}

Any suggestions or tips are greatly appreciated. For now I am simply living with the error. I haven't noticed it impacting performance or introducing any bugs.

I have tried moving the QueryRenderer component directly in the SearchProvider component and it didn't make any difference.



from Cannot update a component while rendering a different component when using QueryRender and React context

"'Connection' object has no attribute '_sftp_live'" when pysftp connection fails

I'd like to catch nicely the error when "No hostkey for host *** is found" and give an appropriate message to the end user. I tried this:

import pysftp, paramiko
try: 
    with pysftp.Connection('1.2.3.4', username='root', password='') as sftp:
        sftp.listdir()
except paramiko.ssh_exception.SSHException as e:
    print('SSH error, you need to add the public key of your remote in your local known_hosts file first.', e)

but unfortunately the output is not very nice:

SSH error, you need to add the public key of your remote in your local known_hosts file first. No hostkey for host 1.2.3.4 found.
Exception ignored in: <function Connection.__del__ at 0x00000000036B6D38>
Traceback (most recent call last):
  File "C:\Python37\lib\site-packages\pysftp\__init__.py", line 1013, in __del__
    self.close()
  File "C:\Python37\lib\site-packages\pysftp\__init__.py", line 784, in close
    if self._sftp_live:
AttributeError: 'Connection' object has no attribute '_sftp_live'

How to nicely avoid these last lines / this "exception ignored" with a try: except:?



from "'Connection' object has no attribute '_sftp_live'" when pysftp connection fails