Size: a a a

2020 September 28

VS

Vadym Shevchenko in React Kyiv
почему нужен только value?
если не будет label в объекте - то не будет корректно отображаться выбранный элемент в самом select
источник

VS

Vadym Shevchenko in React Kyiv
так храните выбранным объект в стейте, а при отправке на сервер отправляйте только значение value
источник

RG

Roman Goncharuk in React Kyiv
Всем привет!

помогите добраться до инпутов

компонент надо стилизовать с помощью Styled Components

import React from "react";
import { useForm } from "react-hook-form";
import { InputItem, WhiteSpace } from "antd-mobile";

import * as styles from "./style.js"

export default function FormRegister() {
 
 return (
   <form onSubmit={handleSubmit(onSubmit)}>
     <styles.FormRegisterCSScopeDIV>
       <styles.FormRegisterEmailInputDIV>
         <InputItem name="example">
           antd-mobile input bottom text
         </InputItem>
       </styles.FormRegisterEmailInputDIV>
       <WhiteSpace />

       <styles.FormRegisterPasswdInputDIV>
         <InputItem type="password">
           antd-mobile input bottom text
         </InputItem>
       </styles.FormRegisterPasswdInputDIV>

       <styles.FormRegisterRequiredFieldDIV>
         {errors.exampleRequired && <span>This field is required</span>}
       </styles.FormRegisterRequiredFieldDIV>

       <styles.FormRegisterButtonInputDIV>
         <input type="submit" value="Submit" />
       </styles.FormRegisterButtonInputDIV>
     </styles.FormRegisterCSScopeDIV>
   </form>
 );
}

вот такая запись

export const inptINPUT = styled.input`
 width: 80%;
 border-radius: 4px;
 /* padding:          2%; */
`
не даёт достучаться до инпутов:

<InputItem name="example">
<InputItem type="password">
<input type="submit" value="Submit" />


а в простом css такая запись

input{
 width: 80%;
 border-radius: 4px;}

вполне регулировала стили для всех трёх инпутов

и вот я не могу понять как в StyledComponents зацепить эти инпуты, чтобы присвоить им стили

дока не проясняет

поможете?

знать бы хоть что гуглить
источник

D

Dmytro in React Kyiv
Roman Goncharuk
Всем привет!

помогите добраться до инпутов

компонент надо стилизовать с помощью Styled Components

import React from "react";
import { useForm } from "react-hook-form";
import { InputItem, WhiteSpace } from "antd-mobile";

import * as styles from "./style.js"

export default function FormRegister() {
 
 return (
   <form onSubmit={handleSubmit(onSubmit)}>
     <styles.FormRegisterCSScopeDIV>
       <styles.FormRegisterEmailInputDIV>
         <InputItem name="example">
           antd-mobile input bottom text
         </InputItem>
       </styles.FormRegisterEmailInputDIV>
       <WhiteSpace />

       <styles.FormRegisterPasswdInputDIV>
         <InputItem type="password">
           antd-mobile input bottom text
         </InputItem>
       </styles.FormRegisterPasswdInputDIV>

       <styles.FormRegisterRequiredFieldDIV>
         {errors.exampleRequired && <span>This field is required</span>}
       </styles.FormRegisterRequiredFieldDIV>

       <styles.FormRegisterButtonInputDIV>
         <input type="submit" value="Submit" />
       </styles.FormRegisterButtonInputDIV>
     </styles.FormRegisterCSScopeDIV>
   </form>
 );
}

вот такая запись

export const inptINPUT = styled.input`
 width: 80%;
 border-radius: 4px;
 /* padding:          2%; */
`
не даёт достучаться до инпутов:

<InputItem name="example">
<InputItem type="password">
<input type="submit" value="Submit" />


а в простом css такая запись

input{
 width: 80%;
 border-radius: 4px;}

вполне регулировала стили для всех трёх инпутов

и вот я не могу понять как в StyledComponents зацепить эти инпуты, чтобы присвоить им стили

дока не проясняет

поможете?

знать бы хоть что гуглить
import { css } from 'styled-components';

const baseInputStyles = css`
 width: 80%;
 border-radius: 4px;
`;

export const inptINPUT = styled.input`
 ${baseInputStyles}
 //...otherElSpecificStyles
`;

export const otherIput = styled.input`
 ${baseInputStyles}
 // ...otherElSpecificStyles
`;

не знаю, правильно ли я понял....так не пробовал? или если нужно для antd компонента

export const StyledInput = styled(InputItem)`
 ${baseInputStyles}
`;
источник

RG

Roman Goncharuk in React Kyiv
Dmytro
import { css } from 'styled-components';

const baseInputStyles = css`
 width: 80%;
 border-radius: 4px;
`;

export const inptINPUT = styled.input`
 ${baseInputStyles}
 //...otherElSpecificStyles
`;

export const otherIput = styled.input`
 ${baseInputStyles}
 // ...otherElSpecificStyles
`;

не знаю, правильно ли я понял....так не пробовал? или если нужно для antd компонента

export const StyledInput = styled(InputItem)`
 ${baseInputStyles}
`;
спасибо

попробую сейчас
источник

RG

Roman Goncharuk in React Kyiv
Dmytro
import { css } from 'styled-components';

const baseInputStyles = css`
 width: 80%;
 border-radius: 4px;
`;

export const inptINPUT = styled.input`
 ${baseInputStyles}
 //...otherElSpecificStyles
`;

export const otherIput = styled.input`
 ${baseInputStyles}
 // ...otherElSpecificStyles
`;

не знаю, правильно ли я понял....так не пробовал? или если нужно для antd компонента

export const StyledInput = styled(InputItem)`
 ${baseInputStyles}
`;
мне даже не просто под antd

а под antd-mobile

надеюсь, что подход одинаково для них сработает
источник
2020 September 29

a

ai in React Kyiv
Ребят подскажите... Не удаетс получить объект из базы mongo по id.
getTicById = async (req, res) => {
   await Tic.findOne({ _id: req.params.id }, (err, tic) => {
   if (err) {
   return res.status(400).json({ success: false, error: err })
}

if (!tic) {
   return res
   .status(404)
   .json({ success: false, error: not found })
}
return res.status(200).json({ success: true, data: tic })
   }).catch(err => console.log(err))
}
Id передается в формате String.
Что это может быть?
источник

DB

Dima Bildin in React Kyiv
Самый очевидный вариант, в коллекции нет айтема с передаваемым id?)
источник

a

ai in React Kyiv
Dima Bildin
Самый очевидный вариант, в коллекции нет айтема с передаваемым id?)
Имеется ввиду в mongoose Schema?
источник

DB

Dima Bildin in React Kyiv
ai
Имеется ввиду в mongoose Schema?
Вообще я имел в виду, в коллекции в базе может не быть айтема, который ты ищешь, я б начал с этого варианта. Пойти руками его поискать, если есть возможность
источник

VS

Vadym Shevchenko in React Kyiv
ai
Имеется ввиду в mongoose Schema?
Проверьте есть ли в самой базе запись с таким ид
источник

a

ai in React Kyiv
Vadym Shevchenko
Проверьте есть ли в самой базе запись с таким ид
Запись есть, однако заметил что в mongo db compass для id указывается тип ObjectId.
источник

a

ai in React Kyiv
Vadym Shevchenko
Проверьте есть ли в самой базе запись с таким ид
{success: false,…}
error: {stringValue: ""${id}"", kind: "ObjectId", value: "${id}", path: "_id", reason: {}}
kind: "ObjectId"
path: "_id"
reason: {}
stringValue: ""${id}""
value: "${id}"
success: false
источник

DB

Dima Bildin in React Kyiv
ai
Запись есть, однако заметил что в mongo db compass для id указывается тип ObjectId.
В доке mongoose говорится Mongoose will cast _id to a MongoDB ObjectId, так что
источник

a

ai in React Kyiv
Dima Bildin
В доке mongoose говорится Mongoose will cast _id to a MongoDB ObjectId, так что
В самой схеме нужно создавать поле id? Просто оно автоматически само создается
источник

DB

Dima Bildin in React Kyiv
ai
В самой схеме нужно создавать поле id? Просто оно автоматически само создается
Предлагаю почитать доку)
https://mongoosejs.com/docs/guide.html#_id
By default, Mongoose adds an _id property to your schemas.
источник

a

ai in React Kyiv
Dima Bildin
Предлагаю почитать доку)
https://mongoosejs.com/docs/guide.html#_id
By default, Mongoose adds an _id property to your schemas.
Ок. Спс
источник

VS

Vadym Shevchenko in React Kyiv
ai
Ребят подскажите... Не удаетс получить объект из базы mongo по id.
getTicById = async (req, res) => {
   await Tic.findOne({ _id: req.params.id }, (err, tic) => {
   if (err) {
   return res.status(400).json({ success: false, error: err })
}

if (!tic) {
   return res
   .status(404)
   .json({ success: false, error: not found })
}
return res.status(200).json({ success: true, data: tic })
   }).catch(err => console.log(err))
}
Id передается в формате String.
Что это может быть?
req.params.id а сам айди тут есть точно?
источник

IH

Ilya Human in React Kyiv
ai
Ребят подскажите... Не удаетс получить объект из базы mongo по id.
getTicById = async (req, res) => {
   await Tic.findOne({ _id: req.params.id }, (err, tic) => {
   if (err) {
   return res.status(400).json({ success: false, error: err })
}

if (!tic) {
   return res
   .status(404)
   .json({ success: false, error: not found })
}
return res.status(200).json({ success: true, data: tic })
   }).catch(err => console.log(err))
}
Id передается в формате String.
Что это может быть?
У монго спец тип для id - ObjectId
db.products.find({"_id": ObjectId("your id")})
источник

RG

Roman Goncharuk in React Kyiv
привет, всем!

подскажите, пожалуйста, почему при установленной границе в 360 пикселей, скачок происходит при 326?

export const FormCSScope = styled.div`
 width: 40%;
 margin: 10% auto;
 padding: 12px;
 background-color: #cce2ff;
 @media (max-width: 360px) {
   width: 96%;
   margin: 40% auto;
   padding: 6px;
 }
`
источник