Wednesday, September 14, 2022

Contact form errors and solutions in React

for => htmlFor

Warning: You provided a `checked` prop to a form field without an `onChange` handler. This will render a read-only field. If the field should be mutable use `defaultChecked`. Otherwise, set either `onChange` or `readOnly`.

Solution: In contact-from.jsx change checked to defaultChecked.

Working with images in React

Depending on API => add / at the end => /folder/ OR remove / from the end => /folder in URL.

import Yourimage from '../images/background_image.png';

let imgStyle= {  backgroundImage: `url(${Yourimage})`};

class ImgComponent extends Component {

render() {    return (      <div style={imgStyle}> </div>    );  }

}

https://medium.com/react-courses/5-top-methods-to-import-and-load-images-dynamically-on-cra-react-local-production-build-855d3ba3e704

https://thewebdev.info/2021/11/14/how-to-fetch-image-from-api-with-react/

https://frontend-digest.com/progressively-loading-images-in-react-107cb075417a

Could not get lock /var/lib/apt/lists/lock. It is held by process...

sudo apt update

[sudo] password for user: 

Reading package lists... Done

E: Could not get lock /var/lib/apt/lists/lock. It is held by process 1420 (packagekitd)

N: Be aware that removing the lock file is not a solution and may break your system.

E: Unable to lock directory /var/lib/apt/lists/

ps aux | grep -i apt

sudo kill processid

sudo lsof /var/lib/dpkg/lock

sudo lsof /var/lib/apt/lists/lock

sudo lsof /var/cache/apt/archives/lock

Tuesday, September 13, 2022

React basic features and tricks

<></> // fragment div container which won't be included in HTML

<CardContainer></CardContainer>

{} // put JavaScript code inside {} in case of unreachable variable

 <React.StrictMode></React.StrictMode> => https://reactjs.org/docs/strict-mode.html

export default function App() {}

// when using function instead class => function App() {} => export default App()

import { function } from './shared/func-do-smth'; // add { } to import just function from component

export const funcName = (a, b, c, d) => { return ( <div></div> );};

// to convert string to number use + => +e.currentTarget.value

Each child in a list should have a unique "key" prop.

const items = [ <>{ el being created }</> ] // dustructure const [items] to get keys

https://stackoverflow.com/questions/32888728/correct-way-to-share-functions-between-components-in-react

https://www.makeuseof.com/must-follow-react-practices/

https://www.educative.io/blog/best-practices-react-developer#5

Using Functional Components and Hooks Instead of Classes

Avoid Using State (If Possible)

Opt for Fragments Instead of Divs Where Possible

Use Object Destructuring For Props

Extract reusable logic into custom hooks


Show more button in React

//

import Button from './shared/btn';
import { useState } from 'react';

export default function Func() {
// set show more state and onClick
const [showMore, setShowMore] = useState(false);
const moreClick = () => {
setShowMore(!showMore);
};
   const html = [];

return (
<>
{showMore ? html : !html}
      <Button
id={'show-more'}
className={'btn'}
value={'Show more'}
onClick={moreClick}
/>{
</>
);
}

     <button

        className='btn'

        onClick={() => setShowMore(!showMore)}

        id='showMore'

      >

        <b>Show More...</b>

      </button>

Sunday, September 11, 2022

Asynchronous JavaScript, AJAX, APIs

https://habr.com/ru/company/timeweb/blog/583588/

https://medium.com/codingthesmartway-com-blog/create-a-rest-api-with-json-server-36da8680136d

https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX

Synchronous code is executed line by line. Each line of code waits previous line finish.

Asynchronous code is executed after task that runs in the "background" finishes. Asynchronous code is non-blocking and do not wait for asynchronous task to finish its work => coordinates behavior of a program over a period of time.

Application programming interfaces allow applications to communicate with each other: DOM API, Geolocation API, Own Class API, free 3rd-party APIs... JSON - most popular API data format.

Saturday, September 10, 2022

Windows Ctrl+Alt+Del equivalent in Linux

Ctrl+Alt+Del in KDE Plasma => shutdown

Ctrl+Alt+F2 // 

login and killall appname

Ctrl+Alt+F1 // return to normal mode

Ctrl+Alt+Backspace => kill X (graphical interface)

sudo systemctl restart display-manager // restart desktop (graphical interface)

sudo /etc/init.d/gdm restart // restart X (graphical interface)

sudo shutdown -r now // reboot

sudo reboot

top // display processes

pstree // display processes tree

ps aux | grep proccessname

Ctrl+C // cancel === exit