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

193
Views
Type error on a function that return a object based on a api get

So basically I want to create a function that does a GET method in my API using an id received as params. As I'm coding a hook, I'm trying to export this function as well. But, I'm suffering from this error: Error that appears

Code:

import { api } from '../services/api';

interface Transaction{
  _id: string,
  name: string,
  amount: number,
  type: 'deposit' | 'withdraw'
  createdAt: string,
}


interface TransactionContextData{
  transactions: Transaction[]
  getTransactionById: (transactionId: String) => Promise<Transaction>
}

const TransactionsContext = createContext<TransactionContextData>({} as TransactionContextData)

export function TransactionsProvider({children}:TransactionsProviderProps){
  const [transactions, setTransactions] = useState<Transaction[]>([])
  useEffect(() => {
    getTransactions()
  }, []);


  async function getTransactionById(transactionId: String){
    api.get(`transactions/${transactionId}`)
    .then((reponse) => {return reponse.data});
  }


  return (
    <TransactionsContext.Provider value={{ transactions, createTransaction, deleteTransaction, updateTransaction, getTransactions, getTransactionById}}>
      {children}
    </TransactionsContext.Provider>
  )
}

export function useTransactions(){
  const context = useContext(TransactionsContext)

  return context
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It just needs a return right before the api.get

about 4 years ago · Juan Pablo Isaza Report
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!