# Joi library not functioning well

**URL:** <https://forum.codewithmosh.com/t/joi-library-not-functioning-well/17069>\
**Category:** React\
**Created:** [December 16, 2022, 1:06pm UTC](https://forum.codewithmosh.com/t/joi-library-not-functioning-well/17069 "2022-12-16T13:06:19Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![OdGreat](https://avatars.discourse-cdn.com/v4/letter/o/5daacb/32.png) [@OdGreat](https://forum.codewithmosh.com/u/OdGreat)\
**Post date:** [December 16, 2022, 1:06pm UTC](https://forum.codewithmosh.com/t/joi-library-not-functioning-well/17069/1 "2022-12-16T13:06:19Z")

</div>

I’m currently in the forms section, in lection 13- Joi to be precised. On initializing the schema object, I get the below error in the console. What could be the cause of this?  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/1/10d2883d25ec9c9fbcc13ac84628db07425fc02d.png)

---

<div class="post-metadata">

**Author:** ![cfkyeahraze](https://avatars.discourse-cdn.com/v4/letter/c/ed8c4c/32.png) [@cfkyeahraze](https://forum.codewithmosh.com/u/cfkyeahraze)\
**Post date:** [December 16, 2022, 5:55pm UTC](https://forum.codewithmosh.com/t/joi-library-not-functioning-well/17069/2 "2022-12-16T17:55:32Z")

</div>

Are you using the same version of joi mosh’s using? If not, the implementation for validation in joi already changed. You can search for the new implementation in google.

---

<div class="post-metadata">

**Author:** ![UniqueNospaceShort](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/uniquenospaceshort/32/1814_2.png) [@UniqueNospaceShort](https://forum.codewithmosh.com/u/UniqueNospaceShort)\
**Post date:** [December 16, 2022, 6:00pm UTC](https://forum.codewithmosh.com/t/joi-library-not-functioning-well/17069/3 "2022-12-16T18:00:54Z")

</div>

Hi, Welcome in here.

Can you specify the exact error message ?  
A red wavy underline is not enough to troubleshoot your problem.

As of myself, I did not use the same versions than Mosh and went with the latest version at the time I took the course. Even though he advise to use the same version as himself in the course, React has gone a long enough way to often not be usable anymore.

Cheers.

---

<div class="post-metadata">

**Author:** ![OdGreat](https://avatars.discourse-cdn.com/v4/letter/o/5daacb/32.png) [@OdGreat](https://forum.codewithmosh.com/u/OdGreat)\
**Post date:** [December 17, 2022, 8:40pm UTC](https://forum.codewithmosh.com/t/joi-library-not-functioning-well/17069/4 "2022-12-17T20:40:52Z")

</div>

Yes I am using the exact version, version 13.4

---

<div class="post-metadata">

**Author:** ![OdGreat](https://avatars.discourse-cdn.com/v4/letter/o/5daacb/32.png) [@OdGreat](https://forum.codewithmosh.com/u/OdGreat)\
**Post date:** [December 17, 2022, 8:42pm UTC](https://forum.codewithmosh.com/t/joi-library-not-functioning-well/17069/5 "2022-12-17T20:42:43Z")

</div>

On hovering on the "x’ symbol, I get this message: Uncaught TypeError: Cannot read properties of undefined (reading ‘string’)

---

<div class="post-metadata">

**Author:** ![UniqueNospaceShort](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/uniquenospaceshort/32/1814_2.png) [@UniqueNospaceShort](https://forum.codewithmosh.com/u/UniqueNospaceShort)\
**Post date:** [December 18, 2022, 12:17pm UTC](https://forum.codewithmosh.com/t/joi-library-not-functioning-well/17069/6 "2022-12-18T12:17:26Z")

</div>

My guess is JOI might not be imported properly.

I see no reason for this message to be about `username`.

---

<div class="post-metadata">

**Author:** ![maverick](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@maverick](https://forum.codewithmosh.com/u/maverick)\
**Post date:** [December 25, 2022, 6:44am UTC](https://forum.codewithmosh.com/t/joi-library-not-functioning-well/17069/7 "2022-12-25T06:44:29Z")

</div>

Show us how you imported Joi!

---

<div class="post-metadata">

**Author:** ![onlyhasbi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/onlyhasbi/32/4608_2.png) [@onlyhasbi](https://forum.codewithmosh.com/u/onlyhasbi)\
**Post date:** [December 31, 2022, 2:26am UTC](https://forum.codewithmosh.com/t/joi-library-not-functioning-well/17069/8 "2022-12-31T02:26:12Z")

</div>

1. do you import joi correctly ?
2. it shoul be :  
const schema = {  
…  
…  
}

---

<div class="post-metadata">

**Author:** ![maverick](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@maverick](https://forum.codewithmosh.com/u/maverick)\
**Post date:** [December 31, 2022, 3:52am UTC](https://forum.codewithmosh.com/t/joi-library-not-functioning-well/17069/9 "2022-12-31T03:52:05Z")

</div>

@onlyhasbi

it’s a class property.  
So, you don’t have to declare it as a variable.

---

<div class="post-metadata">

**Author:** ![onlyhasbi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/onlyhasbi/32/4608_2.png) [@onlyhasbi](https://forum.codewithmosh.com/u/onlyhasbi)\
**Post date:** [December 31, 2022, 7:27am UTC](https://forum.codewithmosh.com/t/joi-library-not-functioning-well/17069/11 "2022-12-31T07:27:11Z")

</div>

are you sure ?  
how about this [example](https://codesandbox.io/s/blissful-easley-tznrb2?file=/src/App.js)  
i put const in schema

to make error showing  
try typing then delete all the text

---

<div class="post-metadata">

**Author:** ![maverick](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@maverick](https://forum.codewithmosh.com/u/maverick)\
**Post date:** [December 31, 2022, 3:57pm UTC](https://forum.codewithmosh.com/t/joi-library-not-functioning-well/17069/12 "2022-12-31T15:57:58Z")

</div>

Yes, I am sure about the thing I said.

For class property, you don’t need to use const / let / var to declare it as a property.

```auto
class ClassName {
    state = {
        ........
    };

    schema = {
        // define schema
    };
    // creating a Joi schema is different in latest version of Joi.
    schema = Joi.object({
        // define schema rules.
    });
}

```

am I clear now?

In your example, you are using functional component.  
I don’t understand what you want to show in your example!

As @UniqueNospaceShort mentioned, the error is above that line.

---

<div class="post-metadata">

**Author:** ![onlyhasbi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/onlyhasbi/32/4608_2.png) [@onlyhasbi](https://forum.codewithmosh.com/u/onlyhasbi)\
**Post date:** [December 31, 2022, 10:17pm UTC](https://forum.codewithmosh.com/t/joi-library-not-functioning-well/17069/13 "2022-12-31T22:17:57Z")

</div>

yes, you’r right. i’m sorry, for my mistake, because when i learn the course, i converting all the lesson in functional way. I forgot that mosh teaching us with class. and i misunderstand about what have you said “it’s a class property”. I make an example just for showing that its work using a const (functional), sorry @maverick 🙏 🙏 🙏

---

<div class="post-metadata">

**Author:** ![maverick](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@maverick](https://forum.codewithmosh.com/u/maverick)\
**Post date:** [January 1, 2023, 4:00am UTC](https://forum.codewithmosh.com/t/joi-library-not-functioning-well/17069/14 "2023-01-01T04:00:23Z")

</div>

@onlyhasbi

No problem and no need to apologize.

We make mistakes all the time.

I just wanted to make sure you understand, in class we don’t have to use const / let / var to create a property.

Functional components are the future of React applications!

Keep rocking.

---

<div class="post-metadata">

**Author:** ![onlyhasbi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/onlyhasbi/32/4608_2.png) [@onlyhasbi](https://forum.codewithmosh.com/u/onlyhasbi)\
**Post date:** [January 1, 2023, 2:45pm UTC](https://forum.codewithmosh.com/t/joi-library-not-functioning-well/17069/15 "2023-01-01T14:45:46Z")

</div>

Keep rocking, yeah 👍

---

<div class="post-metadata">

**Author:** ![AzharUddinSheikh](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/azharuddinsheikh/32/5561_2.png) [@AzharUddinSheikh](https://forum.codewithmosh.com/u/AzharUddinSheikh)\
**Post date:** [February 15, 2023, 2:59pm UTC](https://forum.codewithmosh.com/t/joi-library-not-functioning-well/17069/16 "2023-02-15T14:59:00Z")

</div>

> [@OdGreat](#):
>
> What could be the cause of this?

I wll recommed everyone to use `yup` instead of `joi`

**Basic Example with React Hook Form**

[Schema Validation with React Hook Form](https://react-hook-form.com/get-started#SchemaValidation)
