Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
multiple input field with search hint ReactJs

I have a page in which I load an input component dynamically with a button click, the input component is a custom search bar which displays a hint when the user inputs the search input. The hint is working but i cant get the onclick function to update the input text so as to convert it to an array of string.

import React, { useCallback } from "react";
import { Col, Form } from "react-bootstrap";
const FormComponent = (props) => {
  const arrhandler = useCallback(
    (value) => {
      props.setValue(value);
      props.setResult([]);
    },
    [props.setValue]
  );
  return (
    <Col xs={12} sm={12} md={12} lg={4}>
      <Form.Group className="mb-3">
        <Form.Label>DEPARTURE</Form.Label>
        <Form.Control
          type="text"
          value={props.value}
          onChange={props.handler}
        />
      </Form.Group>
      {props.arr &&
        props.arr.map((port, i) => (
          <div key={i} onClick={() => arrhandler(val.name)}>
            {val.name}
          </div>
        ))}
    </Col>
  );
};
export default FormComponent;

This is my form component

In the parent component i have

import React, { useEffect, useState } from "react";
import { Container, Button } from "react-bootstrap";
import axios from "axios";

const ParentComponent = () => {
  const [forms, setForms] = useState([]);
  const [value, setValue] = useState("");
  const [result, setResult] = useState([]);

  useEffect(() => {
    axios.post(`/api/search/${value}`).then((res) => setResult(res.data));
  }, [value]);

  const newForm = (e) => {
    setForms(forms.concat(<FormComponent key={forms.length} />));
  };

  return (
    <Container>
      <Button
        className="col-lg-5 col-sm-12 mb-2"
        variant="outline-secondary"
        size="lg"
        onClick={newForm}
      >
        Add New Search
      </Button>
      {form.length > 0
        ? forms.map((form) => (
            <FormComponent
              value={form.value}
              handler={(e) => setValue(e.target.value)}
              arr={result}
              setValue={setValue}
              setResult={setResult}
            />
          ))
        : ""}
    </Container>
  );
};

I cant seem to figure out how to update the input field with the onclick function, so that i can store the result in an array.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!