Missing properties in React Typescript component - reactjs

React component
import {Input} from '#xxx/forms';
<Input label="account Name" name="account"/>
input.d.ts
import React, { Ref } from 'react';
import { InputProps as UITKInputProps } from '#xxx/input';
import { WithStyles, Density } from '#xxx/theme';
import { FormFieldProps as FormFieldPropsType } from '../FormField';
import { NecessityStyle } from '../types';
import styles from './styles';
export declare type InputProps = WithStyles<typeof styles> & UITKInputProps & {
name: string;
label?: string;
id?: string;
disabled?: boolean;
FormFieldProps?: Omit<FormFieldPropsType, 'children' | 'name' | 'label'>;
required?: boolean;
necessityStyle?: NecessityStyle;
helperText?: string;
ref?: Ref<any>;
fullWidth?: boolean;
density?: Density;
};
declare const StyledInput: React.ComponentType<Pick<React.PropsWithChildren<InputProps>, "required" | "disabled" | "error" | "hidden" | "dir" | "label" | "slot" | "style" | "title" | "color" | "ref" | "children" | "onBlur" | "onChange" | "onSubmit" | "name" | "onFocus" | "defaultValue" | "id" | "textAlign" | "translate" | "margin" | "className" | "innerRef" | "defaultChecked" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "draggable" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocusCapture" | "onBlurCapture" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "type" | "fullWidth" | "autoFocus" | "value" | "inputProps" | "inputRef" | "readOnly" | "multiline" | "autoComplete" | "endAdornment" | "inputComponent" | "renderSuffix" | "rows" | "rowsMax" | "rowsMin" | "startAdornment" | "disableUnderline" | "density" | "necessityStyle" | "helperText" | "cursorPositionOnFocus" | "emptyReadOnlyMarker" | "highlightOnFocus" | "FormFieldProps"> & import("#material-ui/styles").StyledComponentProps<"disabled" | "input" | "root" | "readOnly" | "focused" | "multiline" | "inputMultiline" | "endAdornment" | "startAdornment" | "lowDensity" | "touchDensity" | "mediumDensity" | "highDensity" | "field">>;
export { StyledInput as Input };
The only required field for <Input /> is name. However, the compiler is complaining:
Type '{ name: string; }' is missing the following properties from type 'Pick<PropsWithChildren, "ref" | "label" | "slot" | "style" | "title" | "children" | "onBlur" | "onChange" | "onSubmit" | "autoComplete" | ... 276 mo
re ... | "FormFieldProps">': slot, style, title, onBlur, and 267 more.
How can I declare Input component inside my component?

While you didn't provide full type definitions for WithStyles and UITKInputProps I'd guess they are having a lot of required props inside. So your InputProps type gets expanded into a huge list of required props from those two types plus explicitly defined props with a required name field. Thus the error.
If you want your InputProps type to have the only required field name you may define it as:
export declare type InputProps
= Partial<WithStyles<typeof styles>>
& Partial<UITKInputProps>
& {
name: string;
label?: string;
id?: string;
disabled?: boolean;
FormFieldProps?: Omit<FormFieldPropsType, 'children' | 'name' | 'label'>;
required?: boolean;
necessityStyle?: NecessityStyle;
helperText?: string;
ref?: Ref<any>;
fullWidth?: boolean;
density?: Density;
};

Related

Type is missing from type (TS2740) - cant override interface

I have a library called "#ww/react-ui-components"
This library contains Paper component, which extends the functionality of Paper from material ui.
This is how the .d.ts file of my Paper looks like (generated in the build):
import React, { RefObject } from 'react';
import { PaperProps } from '#material-ui/core/Paper';
import { WWAttributesProps } from 'hoc/withWindwardAttributes';
export declare type Props = PaperProps & {
rootElRef?: RefObject<any>;
withHoverEffect?: boolean;
};
declare const _default: React.ForwardRefExoticComponent<Pick<import("../hoc/withWindwardAttributes").Attributes & Pick<PaperProps & {
rootElRef?: React.RefObject<any> | undefined;
withHoverEffect?: boolean | undefined;
} & WWAttributesProps, "slot" | "style" | "title" | "ref" | "classes" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "css" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "component" | "elevation" | "square" | "variant" | "innerRef" | "rootElRef" | "withHoverEffect">, "slot" | "style" | "title" | "classes" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "css" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "component" | "elevation" | "square" | "variant" | "innerRef" | "rootElRef" | "withHoverEffect" | "wwComponentName"> & React.RefAttributes<unknown>>;
export default _default;
I have another library called "#ww/ofv-ui-components" which imports Paper from '#ww/react-ui-components"
When I use it, I get the following error:
Type '{ children: Element; }' is missing the following properties from type 'Pick<Attributes & Pick<any, "placeholder" | "onChange" | "children" | "classes" | "defaultValue" | "defaultChecked" | "suppressContentEditableWarning" | "suppressHydrationWarning" | ... 255 more ... | "withHoverEffect">, "placeholder" | ... 262 more ... | "withHoverEffect">': placeholder, onChange, classes, defaultValue, and 258 more.ts
I tried to override the Paper interface by creating modules.d.ts file in "#ww/ofv-ui-components" and used any just to see if it works - which it didnt.
Is there a way to override it somehow? I dont want to suppress the error or ignore it..
I want to fix it properly

Normalize data in object_construct in Snowflake

I'm using Snowflake's Object_Construct to create a JSON.
Use case: Snowflake table has Person Title as
Person Name
Title_1
Title_2
Title_3
in JSON structure, I need to transform this as
"Person_Title"[
{ "Title_1",
"Title_1_desc"
},
{"Title_2",
"Title_2_desc"
},
{"Title_3",
"Title_3_desc"
}
]
Below example outlines the placement of functions to get the output.
Though not sure if you are looking for any sort of dynamism, which following example does not gives -
with cte (Person_Name, Title_1, Title_2, Title_3) as (
select 'name-1','t1-desc-1','t2-desc-1','t3-desc-1' union all
select 'name-2','t1-desc-2','t2-desc-2','t3-desc-2' union all
select 'name-3','t1-desc-3','t2-desc-3','t3-desc-3'
)
select object_construct('Person_title',
array_construct(
object_construct('Title_1',Title_1),
object_construct('Title_2',Title_2),
object_construct('Title_3',Title_3))) output_json
from cte;
+------------------------------+
| OUTPUT_JSON |
|------------------------------|
| { |
| "Person_title": [ |
| { |
| "Title_1": "t1-desc-1" |
| }, |
| { |
| "Title_2": "t2-desc-1" |
| }, |
| { |
| "Title_3": "t3-desc-1" |
| } |
| ] |
| } |
| { |
| "Person_title": [ |
| { |
| "Title_1": "t1-desc-2" |
| }, |
| { |
| "Title_2": "t2-desc-2" |
| }, |
| { |
| "Title_3": "t3-desc-2" |
| } |
| ] |
| } |
| { |
| "Person_title": [ |
| { |
| "Title_1": "t1-desc-3" |
| }, |
| { |
| "Title_2": "t2-desc-3" |
| }, |
| { |
| "Title_3": "t3-desc-3" |
| } |
| ] |
| } |
+------------------------------+
Query with dynamism -
with cte (Person_Name, Title_1, Title_2, Title_3) as (
select 'name-1','t1-desc-1','t2-desc-1','t3-desc-1' union all
select 'name-2','t1-desc-2','t2-desc-2','t3-desc-2'
)
select object_construct('Person_title',
array_agg(object_construct(TITLE_DESC,TITLE))) as output_col
from
(select * from cte
unpivot (title for title_desc in (Title_1, Title_2, Title_3))
)
group by Person_Name;
+------------------------------+
| OUTPUT_COL |
|------------------------------|
| { |
| "Person_title": [ |
| { |
| "TITLE_1": "t1-desc-1" |
| }, |
| { |
| "TITLE_2": "t2-desc-1" |
| }, |
| { |
| "TITLE_3": "t3-desc-1" |
| } |
| ] |
| } |
| { |
| "Person_title": [ |
| { |
| "TITLE_1": "t1-desc-2" |
| }, |
| { |
| "TITLE_2": "t2-desc-2" |
| }, |
| { |
| "TITLE_3": "t3-desc-2" |
| } |
| ] |
| } |
+------------------------------+

404 not found for laravel api Url's

I have api call from react to laravel as backend
const response=await fetch("http://localhost:8000/api/getcandidates/");
but I got response as Kanban.jsx:65
GET http://localhost:8000/api/getcandidates/ 404 (Not Found)
and here is my api.php
Route::get('/getcandidates',[EmployeeController::class,'index']);
Route::get('/getcandidates_schedule',[EmployeeController::class,'scheduleresponse']);
Route::get('/getcandidates_rejection',[EmployeeController::class,'rejectionreponse']);
Route::get('/getcandidates_waiting',[EmployeeController::class,'waitingresponse']);
Route::post('/add_employee_first',[EmployeeController::class,'store']);
Route::post('/updatecolumn',[EmployeeController::class,'updatecolumn']);
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
output of php artisan route:list:
Domain | Method | URI | Name | Action | Middleware |
+--------+----------+----------+------+---------+------------+
| | GET|HEAD | / | | Closure | web |
| | GET|HEAD | api/user | | Closure | api |
| | | | | | auth:api |
+--------+----------+----------+------+---------+------------
Please help me .

TypeError: render is not a function while using React Context along with React Router

I need to set up a user state that can be called from different components. This setup uses React Router and React Context.
The React context contains just a single state that keeps track of the user's name.
At the top-level i.e App I have passed all the children on to the provider. But I get an error
TypeError: render is not a function
My UserContext code:
const UserContext = createContext();
export const UserProvider = (props) => {
const [user, setUser] = useState("");
return (
<UserContext.Provider value={[user, setUser]}>
{props.children}
</UserContext.Provider>
);
};
export default UserContext;
My App code :
function App() {
return (
<UserProvider>
<Router>
<div>
<Nav />
<Switch>
<Route exact path="/" component={Signup} />
<Route exact path="/signin" component={SignIn} />
<Route path="/register" component={UserRegister} />
<Route path="/homepage/:user" component={Homepage} />
</Switch>
</div>
</Router>
</UserProvider>
);
}
export default App;
The entrie error log:
TypeError: render is not a function
updateContextConsumer
G:/WebDevelopmentFolder/trinkerrchallenge/node_modules/react-dom/cjs/react-dom.development.js:18747
18744 | {
18745 | ReactCurrentOwner$1.current = workInProgress;
18746 | setIsRendering(true);
> 18747 | newChildren = render(newValue);
| ^ 18748 | setIsRendering(false);
18749 | } // React DevTools reads this flag.
18750 |
View compiled
beginWork
G:/WebDevelopmentFolder/trinkerrchallenge/node_modules/react-dom/cjs/react-dom.development.js:19114
19111 | return updateContextProvider(current, workInProgress, renderLanes);
19112 |
19113 | case ContextConsumer:
> 19114 | return updateContextConsumer(current, workInProgress, renderLanes);
| ^ 19115 |
19116 | case MemoComponent:
19117 | {
View compiled
HTMLUnknownElement.callCallback
G:/WebDevelopmentFolder/trinkerrchallenge/node_modules/react-dom/cjs/react-dom.development.js:3945
3942 | function callCallback() {
3943 | didCall = true;
3944 | restoreAfterDispatch();
> 3945 | func.apply(context, funcArgs);
| ^ 3946 | didError = false;
3947 | } // Create a global error event handler. We use this to capture the value
3948 | // that was thrown. It's possible that this error handler will fire more
View compiled
invokeGuardedCallbackDev
G:/WebDevelopmentFolder/trinkerrchallenge/node_modules/react-dom/cjs/react-dom.development.js:3994
3991 | // errors, it will trigger our global error handler.
3992 |
3993 | evt.initEvent(evtType, false, false);
> 3994 | fakeNode.dispatchEvent(evt);
| ^ 3995 |
3996 | if (windowEventDescriptor) {
3997 | Object.defineProperty(window, 'event', windowEventDescriptor);
View compiled
invokeGuardedCallback
G:/WebDevelopmentFolder/trinkerrchallenge/node_modules/react-dom/cjs/react-dom.development.js:4056
4053 | function invokeGuardedCallback(name, func, context, a, b, c, d, e, f) {
4054 | hasError = false;
4055 | caughtError = null;
> 4056 | invokeGuardedCallbackImpl$1.apply(reporter, arguments);
4057 | }
4058 | /**
4059 | * Same as invokeGuardedCallback, but instead of returning an error, it stores
View compiled
beginWork$1
G:/WebDevelopmentFolder/trinkerrchallenge/node_modules/react-dom/cjs/react-dom.development.js:23964
23961 | } // Run beginWork again.
23962 |
23963 |
> 23964 | invokeGuardedCallback(null, beginWork, null, current, unitOfWork, lanes);
| ^ 23965 |
23966 | if (hasCaughtError()) {
23967 | var replayError = clearCaughtError(); // `invokeGuardedCallback` sometimes sets an expando `_suppressLogging`.
View compiled
performUnitOfWork
G:/WebDevelopmentFolder/trinkerrchallenge/node_modules/react-dom/cjs/react-dom.development.js:22776
22773 |
22774 | if ( (unitOfWork.mode & ProfileMode) !== NoMode) {
22775 | startProfilerTimer(unitOfWork);
> 22776 | next = beginWork$1(current, unitOfWork, subtreeRenderLanes);
| ^ 22777 | stopProfilerTimerIfRunningAndRecordDelta(unitOfWork, true);
22778 | } else {
22779 | next = beginWork$1(current, unitOfWork, subtreeRenderLanes);
View compiled
workLoopSync
G:/WebDevelopmentFolder/trinkerrchallenge/node_modules/react-dom/cjs/react-dom.development.js:22707
22704 | function workLoopSync() {
22705 | // Already timed out, so perform work without checking if we need to yield.
22706 | while (workInProgress !== null) {
> 22707 | performUnitOfWork(workInProgress);
22708 | }
22709 | }
22710 |
View compiled
renderRootSync
G:/WebDevelopmentFolder/trinkerrchallenge/node_modules/react-dom/cjs/react-dom.development.js:22670
22667 |
22668 | do {
22669 | try {
> 22670 | workLoopSync();
| ^ 22671 | break;
22672 | } catch (thrownValue) {
22673 | handleError(root, thrownValue);
View compiled
performSyncWorkOnRoot
G:/WebDevelopmentFolder/trinkerrchallenge/node_modules/react-dom/cjs/react-dom.development.js:22293
22290 | }
22291 | } else {
22292 | lanes = getNextLanes(root, NoLanes);
> 22293 | exitStatus = renderRootSync(root, lanes);
| ^ 22294 | }
22295 |
22296 | if (root.tag !== LegacyRoot && exitStatus === RootErrored) {
View compiled
scheduleUpdateOnFiber
G:/WebDevelopmentFolder/trinkerrchallenge/node_modules/react-dom/cjs/react-dom.development.js:21881
21878 | // root inside of batchedUpdates should be synchronous, but layout updates
21879 | // should be deferred until the end of the batch.
21880 |
> 21881 | performSyncWorkOnRoot(root);
| ^ 21882 | } else {
21883 | ensureRootIsScheduled(root, eventTime);
21884 | schedulePendingInteractions(root, lane);
View compiled
updateContainer
G:/WebDevelopmentFolder/trinkerrchallenge/node_modules/react-dom/cjs/react-dom.development.js:25482
25479 | }
25480 |
25481 | enqueueUpdate(current$1, update);
> 25482 | scheduleUpdateOnFiber(current$1, lane, eventTime);
25483 | return lane;
25484 | }
25485 | function getPublicRootInstance(container) {
View compiled
(anonymous function)
G:/WebDevelopmentFolder/trinkerrchallenge/node_modules/react-dom/cjs/react-dom.development.js:26021
26018 |
26019 |
26020 | unbatchedUpdates(function () {
> 26021 | updateContainer(children, fiberRoot, parentComponent, callback);
| ^ 26022 | });
26023 | } else {
26024 | fiberRoot = root._internalRoot;
View compiled
unbatchedUpdates
G:/WebDevelopmentFolder/trinkerrchallenge/node_modules/react-dom/cjs/react-dom.development.js:22431
22428 | executionContext |= LegacyUnbatchedContext;
22429 |
22430 | try {
> 22431 | return fn(a);
| ^ 22432 | } finally {
22433 | executionContext = prevExecutionContext;
22434 |
View compiled
legacyRenderSubtreeIntoContainer
G:/WebDevelopmentFolder/trinkerrchallenge/node_modules/react-dom/cjs/react-dom.development.js:26020
26017 | } // Initial mount should not be batched.
26018 |
26019 |
> 26020 | unbatchedUpdates(function () {
| ^ 26021 | updateContainer(children, fiberRoot, parentComponent, callback);
26022 | });
26023 | } else {
View compiled
render
G:/WebDevelopmentFolder/trinkerrchallenge/node_modules/react-dom/cjs/react-dom.development.js:26103
26100 | }
26101 | }
26102 |
> 26103 | return legacyRenderSubtreeIntoContainer(null, element, container, false, callback);
26104 | }
26105 | function unstable_renderSubtreeIntoContainer(parentComponent, element, containerNode, callback) {
26106 | if (!isValidContainer(containerNode)) {
View compiled
Module.<anonymous>
G:/WebDevelopmentFolder/trinkerrchallenge/src/index.js:6
3 | import "./index.css";
4 | import App from "./App";
5 |
> 6 | ReactDOM.render(
7 | <React.StrictMode>
8 | <App />
9 | </React.StrictMode>,
View compiled
Module../src/index.js
http://localhost:3000/static/js/main.chunk.js:1581:30
__webpack_require__
G:/WebDevelopmentFolder/trinkerrchallenge/webpack/bootstrap:851
848 |
849 | __webpack_require__.$Refresh$.init();
850 | try {
> 851 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
| ^ 852 | } finally {
853 | __webpack_require__.$Refresh$.cleanup(moduleId);
854 | }
View compiled
fn
G:/WebDevelopmentFolder/trinkerrchallenge/webpack/bootstrap:150
147 | );
148 | hotCurrentParents = [];
149 | }
> 150 | return __webpack_require__(request);
| ^ 151 | };
152 | var ObjectFactory = function ObjectFactory(name) {
153 | return {
View compiled
1
http://localhost:3000/static/js/main.chunk.js:1595:18
__webpack_require__
G:/WebDevelopmentFolder/trinkerrchallenge/webpack/bootstrap:851
848 |
849 | __webpack_require__.$Refresh$.init();
850 | try {
> 851 | modules[moduleId].call(module.exports, module, module.exports, hotCreateRequire(moduleId));
| ^ 852 | } finally {
853 | __webpack_require__.$Refresh$.cleanup(moduleId);
854 | }
View compiled
checkDeferredModules
G:/WebDevelopmentFolder/trinkerrchallenge/webpack/bootstrap:45
42 | }
43 | if(fulfilled) {
44 | deferredModules.splice(i--, 1);
> 45 | result = __webpack_require__(__webpack_require__.s = deferredModule[0]);
| ^ 46 | }
47 | }
48 |
View compiled
Array.webpackJsonpCallback [as push]
G:/WebDevelopmentFolder/trinkerrchallenge/webpack/bootstrap:32
29 | deferredModules.push.apply(deferredModules, executeModules || []);
30 |
31 | // run deferred modules when all chunks ready
> 32 | return checkDeferredModules();
| ^ 33 | };
34 | function checkDeferredModules() {
35 | var result;

Foreach and getting tags and categories from other tables

I had hard time to think about good title, but I hope that this explains.
Posts table
+----+---------+-----------------+
| id | title | text |
+----+---------+-----------------+
| 1 | Title 1 | This is example |
| 2 | Title 2 | This is example |
| 3 | Title 3 | This is example |
+----+---------+-----------------+
Tags table
+----+--------+
| id | tag |
+----+--------+
| 1 | jQuery |
| 2 | PHP |
| 3 | Stack |
+----+--------+
Category table
+----+------------+
| id | category |
+----+------------+
| 1 | Category 1 |
| 2 | Category 2 |
| 3 | Category 3 |
+----+------------+
Post tags relation table (same thing with category)
+---------+--------+
| post_id | tag_id |
+---------+--------+
| 1 | 1 |
| 1 | 2 |
| 2 | 3 |
+---------+--------+
This is the result what i want to see in my view:
+---------+------------------+--------------------+------------+
| Title | Text | Tags | Categories |
+---------+------------------+--------------------+------------+
| Title 1 | This is example | jQuery, PHP | Category 2 |
| Title 2 | This is example | Stack | Category 1 |
| Title 3 | This is example | jQuery, PHP, Stack | Category 1 |
+---------+------------------+--------------------+------------+
In my controller i have
public function index()
{
$posts = Posts::orderBy('title', 'ASC')->get();
return View::make('posts', array(
'posts' => $posts)
);
}
And in my view I can list all posts with foreach loop
#foreach ($posts as $post)
Title: {{ $post->title }}
Text: {{ $post->text }}
Tags: ?
Categories: ?
#endforeach
Question is that what is best way to get tags and categories for each post inside foreach loop?
Shakil's tips was right on the spot and i found what i was looking for. I am surprised that it was so easy to achieve. Here is what i did:
Posts -model
class Posts extends Eloquent
{
protected $table = 'posts';
public function tags()
{
return $this->belongsToMany('Tags', 'post_tags', 'post_id', 'tag_id');
}
public function category()
{
return $this->belongsToMany('Category', 'post_categories', 'post_id', 'category_id');
}
}
View
#foreach ($posts as $post)
Title: {{ $post->title }}
Text: {{ $post->text }}
Tags:
#foreach ($post->tags as $tag)
{{ $tag }}
#endforeach
Categories:
#foreach ($post->categories as $category)
{{ $category }}
#endforeach
#endforeach
Thanks for all for your help!

Resources