Kaynağa Gözat

Update Tag Input

Tatiana Inama 7 yıl önce
ebeveyn
işleme
381aaaec49

+ 2 - 1
recipes/src/components/TagInput/index.tsx

@@ -26,8 +26,9 @@ class TagInput extends Component<TagInputProps, TagInputState> {
   
   constructor(props: TagInputProps) {
     super(props);
+    const tags = props.initialValues ? props.initialValues.map(this.mkTag) : [];
     this.state = {
-      tags: [],
+      tags: tags,
       newTag: '',
     }
   }

+ 10 - 2
recipes/src/containers/Recipes/Create.tsx

@@ -36,7 +36,9 @@ class CreateRecipe extends React.Component<CreateRecipeProps, CreateRecipeState>
   constructor(props: any) {
     super(props);
     this.state = {
-      form: { ..._recipe }
+      form: { 
+        ..._recipe,
+      }
     }
   }
 
@@ -140,7 +142,13 @@ class CreateRecipe extends React.Component<CreateRecipeProps, CreateRecipeState>
               </Cell>
               <Cell columns={12}>
                 <TagInput
-                  onNewTag={(tag) => { console.log(tag) }}
+                  initialValues={form.tags}
+                  onNewTag={(tags) => { this.setState({
+                    form: {
+                      ...this.state.form,
+                      tags,
+                    }
+                  })}}
                 />
               </Cell>
             </Row>