Tuesday, September 20, 2022

Understanding what are props in React

// search-box.jsx

import './search-box.scss';

const SearchBox = (props) => (
<input
className='search'
type='search'
placeholder={props.placeholder}
onChange={props.onSearchChange}
/>
);

export default SearchBox;

// is same as above but worse in terms of code

import './search-box.scss';

export const SearchBox = ({ placeholder, onSearchChange }) => (
<input
className='search'
type='search'
placeholder={placeholder}
onChange={onSearchChange}
/>
);

export default SearchBox;

// App.js

<SearchBox
placeholder='Search...'
onSearchChange={this.onSearchChange}
/>

//

`value` prop to a form field without an `onChange` handler

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

<input value='' />

// change to defaultValue=''

Pass multiple parameters to onClick function

Function parameters are the names listed in the function's definition. Function arguments are the real values passed to the function. Parameters are initialized to the values of the arguments supplied.

If parameter is function (clickHandler in this case), pass argument as function => clickHandler();

import Button from './btn';
import { useNavigate } from 'react-router-dom';

export default function BtnNav(footer, btnText, btnLink, clickHandler) {
const navigate = useNavigate();
return (
<ul className={`${footer}__nav`}>
{btnText.map((el, index) => (
<li key={`${footer}-k-${index}`}>
<Button
id={`${footer}-btn-${index}`}
className={`${footer}-btn-${index}`}
onClick={() => {
navigate(btnLink[index]);
clickHandler();
}}

content={el}
/>
</li>
))}
</ul>
);
}

// to avoid message error clickHandler, pass empty function as onClick in necessary components

const falseClick = () => {};

https://blog.openreplay.com/3-ways-of-passing-multiple-parameters-to-the-onclick-handler-in-react

https://stackoverflow.com/questions/26069238/call-multiple-functions-onclick-reactjs

Monday, September 19, 2022

Make footer stick bottom with flex

index.html

<div class="wrapper" id="root"></div>

<div class="wrapper"> // content container

  <header></header>

  <main></main>

  <footer></footer>

</div>

main {
flex: 1;
}
.wrapper {
display: flex;
flex-direction: column;
justify-content: space-between;
height: 100vh;
}

https://stackoverflow.com/questions/40515142/how-to-make-a-sticky-footer-in-react

https://stackoverflow.com/questions/71478639/footer-not-sticking-to-the-bottom-of-the-page-in-react

https://stackoverflow.com/questions/10099422/flushing-footer-to-bottom-of-the-page-twitter-bootstrap

https://stackoverflow.com/questions/55541850/how-to-make-footer-stay-at-bottom-of-the-page-with-flex-box

tailwindcss and daysiui in React

https://tailwindcss.com/docs/guides/create-react-app

https://daisyui.com/docs/use/

index.css // add these lines

@tailwind base;
@tailwind components;
@tailwind utilities;

tailwind.config.js // paste into

/** @type {import('tailwindcss').Config} */
module.exports = {
content: ['./src/**/*.{html,js,jsx}'],
theme: {
extend: {},
},
plugins: [require('daisyui')],
};

package.json // consider to install

"devDependencies": {
"autoprefixer": "^10.4.8",
"node-sass": "^7.0.1",
"postcss": "^8.4.16",
"react-icons": "^4.4.0"
}

postcss.config.js

module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}

//

Show changes in specific file using git

git show filename // will show the log message and textual diff

git status -s // list modified files

git diff filename

git log --follow filename // list commits only

git log --follow -p -- filename // entire history of file modifications

git blame <filename> // show who changed file

Sunday, September 18, 2022

Links, routes, page navigation in React

import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';

https://www.loginradius.com/blog/engineering/react-router-basics/

App.js // do not toutch index.js


https://stackoverflow.com/questions/69832748/error-error-a-route-is-only-ever-to-be-used-as-the-child-of-routes-element