React Machine coding
https://github.com/imran-mind/reactjs-frontendeval-challenges/tree/main
website:
https://sadanandpai.github.io/frontend-mini-challenges/
question
bar chart component
https://github1s.com/imran-mind/reactjs-frontendeval-challenges/blob/main/bar-chart
steps:
fetch the data(text) using useEffect
create the map to group the x-axis data -> {x-axis(value) : y-axis(count)} -> {1:10,2:18} --> forEach loop -> key is present in map then increment by one , otherwise add the key with initial value 1
now set the map to freq state
prepare data for y-axis using useEffect (since freq changes in every call) ~ if max value is 15 then ---> y-axis --> [20,10,0] ,
if max value is 35 then ---> y-axis --> [40,3020,10,0]
- now set the array to yAxis state
now create the bar chart (x-axis(count),y-axis(array) )
- App -> container -> box -> box-y-axis
Drag N Drop Task Manager App
https://github1s.com/imran-mind/reactjs-frontendeval-challenges/blob/main/task-app-drag-n-drop
functionality
initially added todo
we can drag and drop to doing and done , viseversa
edit and delete todo
steps:
ui --> heading,input, 3section(todo,doing,done)
- App-> h1,input,3section(board->todo->[h2(todo-col),div(inputText,btn(edit,delete))],doing,done)
logic
input
onChange --> setValue(e.target.value)
onKeyDown --> if(e.keyCode === 13) (enter key is pressed)
obj={id: Date.now(),status: TODO,title:value}
setTask((prevTask)=>[...prevTask, obj])
setValue("")
now map through task array in todo,doing and done section
- task.status === TODO / DOING / DONE
each todo
onDrag -->setDragTask(task)
draggable
TODO , DOING ,DONE --> applied on 3 section
onDrop -->handleOnDrop
status = e.target.getAttribute('data-status')
if(status === TODO /DOING /DONE) --> handleDrangNDrop(TODO /DOING /DONE) ->copy task and update status
onDragOver
data-status={TODO/DOING/DONE}
Delete ->copy task and filter out that id
Edit ->
Image Carousel
https://github1s.com/imran-mind/reactjs-frontendeval-challenges/blob/main/image-carousel
logic
fetch data from url with useEffect
then filter out data such that it only includes '.jpg'
then extract only img url in '--.jpg'
set that list of img url to setImage
initially index =0
handleClick on button
< --> handleClick('left') -> if(index===0)
> -->handleClick('right') -> if(index===lastIdx)
auto slide the image using setInterval-->handleClick('right') in useEffect
infinite scroll
https://github1s.com/imran-mind/reactjs-frontendeval-challenges/blob/main/infinite-scrolling
logic
useEffect -> to call firstPage data on initial load
seImages to set images
then map images -> <img />
dummy element ->useRef ->(loaderRef)
useEffect -> to call nextPages from 2 onwards
create IntersectionObserver--> to observe and unobserve loaderRef
then fetch the data -->append to seImages
and then increment the page count
Job Board
https://github1s.com/imran-mind/reactjs-frontendeval-challenges/blob/main/job-board
logic
2 api call ---> 1st for get all ids, and 2nd to get data to displayed based on id --> at a time call 9 ids
create a common fuction to call api -> getData()
useEffect
fetchPostIds() ->fetchPostMetaData()
-> data transformation
getJobTitle()
getJobInfo()
getFormattedDate()
now store the formatted data into postMetadata
now map through postMetadata in cards
handle load more functionality --> 6 more cards
Tic Tac Toe
https://github1s.com/imran-mind/reactjs-frontendeval-challenges/blob/main/tic-toc-toe
logic
initially create matrix array of 9 --->Array(9).fill(null)
map matrix array --> pass id
event delegation --> only add a click event to parent not every child --> handleUserClick()--> update value to matrix
useEffect --> decideWinner() when matrix change
resetGame()
Product Filter App
https://github.com/imran-mind/reactjs-frontendeval-challenges/tree/main/product-filter-app
logic
filter ---> map to display button --> event delegation --> only add a click event to parent not every child --> handleFilterClick()--> toggle activeFilter value --> if already present then remove , otherwise add
filteredData --> map to display product cart
useEffect --> filterProducts() when activeFilter change
Selectable Grid
two factor input
https://github1s.com/imran-mind/reactjs-frontendeval-challenges/blob/main/OTP-code-input
logic
create emtyArray =[' ', ' ', ' ', ' '] -->then map it and return <input>
const refs = [useRef(), useRef(), useRef(), useRef()];
const [inputs, setInputs] = useState(emptyArr);
logic
refs[0].current.focus(); --> default focus to first input using useEffect
input
onChange-> handleInputChange(e,i)
if not a Number , then return
ref to focus on next input --> refs[i+1].current.focus()
create a copy of inputs, before update --> val
setInputs -> to set updated value
onKeyDown -> backspace for delete ->
ref to focus on previous input --> refs[i-1].current.focus()
create a copy of inputs, before update --> " "
setInputs -> to set updated value
onPaste ->
maxLength='1'
key={i}
value={inputs[i]}
ref ={refs[i]}--> to give focus to input
type='text'
button -> onSubmit -->
check if any input box is empty , then change color to red ->
if input ===CODE then alert success or otherwise fail
Subscribe to my newsletter
Read articles from Gokul Pisharody directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Gokul Pisharody
Gokul Pisharody
I am a full-stack developer with expertise in HTML, CSS, and JavaScript, as well as frameworks like React-Redux, Context API, Node.js, and Express. I have experience building scalable web applications with SQL and NoSQL databases like MongoDB. Additionally, I specialize in MERN Stack development, which includes MongoDB, Express, React, and Node.js. In addition to my technical skills, I am also proficient in Python and Flask, which I use to develop server-side functionality. I am passionate about creating responsive websites and mobile applications using the latest design and development techniques. As a dedicated learner, I am always seeking new opportunities to improve my skills and stay up-to-date with the latest technologies.