@@ -2,6 +2,29 @@ import { useState } from "react";
22import axios from "axios" ;
33import "../../styles/pages/activities/getDefinition.css" ;
44
5+ const WordContent = ( { definition} ) => {
6+ if ( definition ) {
7+ return (
8+ < div className = "word-content" >
9+ {
10+ definition ?. map ( ( def , index ) => (
11+ < div className = "word-definition" >
12+ < div key = { index } > < em > Definition: </ em > { def . definition } </ div >
13+ < div key = { index } > < em > Example: </ em > { def . example } </ div >
14+ </ div >
15+ )
16+ )
17+ }
18+ </ div >
19+ )
20+ }
21+ return (
22+ < div className = "word-content" >
23+ < div className = "no-definition" > Word not found!</ div >
24+ </ div >
25+ )
26+ }
27+
528export const SearchWord = ( ) => {
629 const [ term , setTerm ] = useState ( ) ;
730 const [ definition , setDefinition ] = useState ( [ ] ) ;
@@ -20,7 +43,7 @@ export const SearchWord = () => {
2043 if ( allDefinitions . length ) {
2144 setDefinition ( allDefinitions ) ;
2245 } else {
23- setDefinition ( "No definition found." ) ;
46+ setDefinition ( null ) ;
2447 }
2548 } )
2649 . catch ( ( error ) => console . error ( error ) ) ;
@@ -36,6 +59,7 @@ export const SearchWord = () => {
3659 }
3760 } ;
3861
62+ console . log ( definition )
3963 return (
4064 < div className = "rquote-root" >
4165 < h1 > Your Virtual Dictionary</ h1 >
@@ -52,14 +76,7 @@ export const SearchWord = () => {
5276 />
5377 < button onClick = { handleSearch } className = "word-button" > Search</ button >
5478 </ div >
55- < div className = "word-content" >
56- { definition . map ( ( def , index ) => (
57- < div className = "word-definition" >
58- < div key = { index } > < em > Definition: </ em > { def . definition } </ div >
59- < div key = { index } > < em > Example: </ em > { def . example } </ div >
60- </ div >
61- ) ) }
62- </ div >
79+ < WordContent definition = { definition } />
6380 </ div >
6481 ) ;
65- } ;
82+ } ;
0 commit comments