Bài đăng

TypeORM should using repository or query buider ?

TypeORM should using repository or query buider ? Both repository and query builder approaches can be used to query data in TypeORM, depending on the situation and your preference. The repository pattern in TypeORM provides a more intuitive and straightforward approach to interacting with the database. It allows you to define methods in the repository to perform CRUD (create, read, update, delete) operations on objects in the database. These methods can also be used to perform more complex queries, such as using JOIN or GROUP BY queries.  The repository pattern The repository pattern also allows you to focus on the object rather than the query. The query builder in TypeORM provides a more flexible approach to building database queries. It allows you to build complex queries by combining multiple statements and enables you to create more interactive queries with the database.  The query builder The query builder also allows you to have more control over creating queries and can optimize

Type of children prop in React Typescript

Hình ảnh
Type of children prop in React Typescript In difference contexts, you can choose type of 'children' prop as following types: 1. Type JSX.Element: using only for single React Element  If 'children' is list React Element, we can define: children: JSX.Element | JSX.Element[]  export default ICustomPageContext; type Props = { title: string, children: JSX.Element, }; const Page = ({ title, children }: Props) => ( <div> <h1> { title } </h1> { children } </div> ); 2. Type ReactChild: using for single React Element, string, number If 'children' is list React Elements, list string, list number, we can define: children: ReactChild | ReactChild[]  type Props = { title: string; children?: | React.ReactChild | React.ReactChild[]; }; 3. Type ReactNode: using for multiple React Elements, strings, number. This is general type for 'children' If you cannot identify the specific type of 'children', you ju

Typescript: How to Define interface with key in Enum

Hình ảnh
Typescript: How to Define interface with key in Enum Can we define the interface with key in Enum ? We cannot using enum as key in interface But we can using enum as key in Type define. Please see example bellow:  enum AddressTypes { WARD = 'ward' , DISTRICT = 'district' , PROVINCE = 'province' , COUNTRY = 'country' , } // Solution 1: type PersonAddress = Record < AddressTypes , string >; // Solution 2: type PersonAddress2 = { [ key in AddressTypes ]: string }; Conclusion We can only using Enum as key in Type defination, we cannot using enum as key in interface defination. If you have any question, please comment bellow! Thanks !

Why we should Avoid using UNSAFE componentWillMount, componentWillReceiveProps, componentWillUpdate

Hình ảnh
  Avoid using UNSAFE componentWillMount (UNSAFE_componentWillMount) Using componentWillMount for init state ? We can using `state initialization` or init state in constructor => we don't need using componentWillMount import React from " react "; class ExampleComponent extends React. Component { state = { currentColor: this . props . defaultColor , palette: " rgb " } ; } class ExampleComponent2 extends React. Component { constructor (props) { super (props); this . state = { currentColor: this . props . defaultColor , palette: " rgb " } ; } } Using componentWillMount for fetching external Data ? import React from " react "; class ExampleComponent extends React. Component { state = { externalData: null , } ; componentDidMount () { this . _asyncRequest = loadMyAsyncData (). then ( externalData => { this . _asyncRequest = null ; this . setState

Public key and Private key: Difference in the context encryption and signing (JWT)

Hình ảnh
What is  Public Key and Private Key ? The use case of Public Key and Private Key in Signing and Encryption ? For Signing (JWT): Private key is owned by the issuer. The issuer use the private key to make signature Public key can be share with all parties that need to verify the signature   For Encryption:  Private key is owned by the recipient. Private key use to decrypt data Public key can be shareed to any party that want to send sensitive data to the reciptient. Public key use to encrypt data Reference:  https://stackoverflow.com/questions/60538047/jwt-private-public-key-confusion

Typescript/React: How to define interdependency properties in Interface

Hình ảnh
You want to define the interface with properties have constraint with each other You want to define the interface with properties interdependency You want to define inteface have values interdependency  Please follow the example code bellow, for every cardType value we is required related fields: interface ProductCardCommonProps { } interface ProductCardSimple extends ProductCardCommonProps { cardType: 'simple' , price: number } interface ProductCardOptions extends ProductCardCommonProps { cardType: 'options' , fromPrice: string, toPrice: number } interface ProductCardForSale extends ProductCardCommonProps { cardType: 'forSale' , originPrice: number, salePrice: number } const ProductCard = (props: ProductCardSimple | ProductCardOptions | ProductCardForSale) => { return ( <div className = "col mb-5" > <Card className = "h-100 text-center" > <Badge className = "bg-dark posi

MSAL: Difference between Public Client Application And Confidential Client Application

Hình ảnh
What is Azure Confidential Client Application Confidentical Client Appliction refer to apps which run in server (example Web apps, web APIs, ...). They is difficult to access, therefore can they can store application secret. Confidential Client Application only expose App ID to the browser, but App Secret is store in server. What is Azure Public Client Application  Public Client Application refer to apps run on devices (android, iOS, ...), desktop computer, or browser. They are not strust to safely, therefore they cannot to store Secret Key. They only connect to Web APIs with on-behalft-of the user.  References:  https://docs.microsoft.com/en-us/azure/active-directory/develop/msal-client-applications