Hi guys I'm new to TypeScript,
I'm trying to use an API to return a response payload which I am then setting as the state of my fishes array using useState hook and then using the state stored in that array to allocate data in my typesScript interface which can then be rendered in my react component using the interface object. But it renders an undefined error.
Following is the response payload being used to set the state of the fishes array
const [fishes, setFishes] = useState([])
useEffect(() => {
FetchApiData(species).then(response => setFishes(response))
}, [])
I am allocating the index element from the useState array as follow:
let fishData = fishes[0]
I have a response payload in fishData as follows which has keys with spaces in them:
{
"Fishery Management": "<ul>\n<li>NOAA Fisheries with the Gulf of Mexico and South Atlantic Fishery Management Councils manage red snapper in the United States.</li>\n<li>In the Gulf of Mexico, managed under the Fishery Management Plan for the Reef Fish Resources of the Gulf of Mexico:\n<ul>\n<li>A rebuilding plan was implemented in 2005 with the goal of rebuilding the Gulf of Mexico red snapper stock by 2032.</li>\n<li>Annual catch limits for the commercial and recreational fisheries.</li>\n<li>Commercial fishermen must have a permit to harvest red snapper. Through the individual fishing quota (catch shares) program, they may harvest their quotas whenever they choose and must report how much they harvest.</li>\n<li>A minimum size limit protects the spawning stock and juveniles.</li>\n<li>For more information, visit NOAA Fisheries Southeast Regional Office’s Gulf of Mexico Red Snapper Management website.</li>\n</ul>\n</li>\n<li>In the South Atlantic, managed under the Fishery Management Plan for the Snapper-Grouper Fishery of the South Atlantic Region:\n<ul>\n<li>A rebuilding plan was implemented in 2010 with the goal of rebuilding the South Atlantic red snapper stock by 2044. It allows for limited harvest of red snapper as the population continues to grow. </li>\n<li>In 2010 and 2011, regulations prohibited harvest of red snapper in the South Atlantic to protect the population from too much fishing pressure and to allow the number of fish to increase.</li>\n<li>Limited harvest was allowed in 2012-2014. Harvest was prohibited in 2015 and 2016.</li>\n<li>For more information, visit the South Atlantic Fishery Management Council’s Red Snapper Regulations website or NOAA Fisheries Southeast Regional Office’s South Atlantic Snapper-Grouper Management page.</li>\n</ul>\n</li>\n<li>State management consistency with federal management\n<ul>\n<li>In the Gulf of Mexico, recreational state management measures are very different from recreational federal management measures.</li>\n<li>In the South Atlantic, state management measures are fairly consistent with the federal management measures noted above. Some states, such as South Carolina and Georgia, automatically adopt federal regulations while others have separate regulations.</li>\n</ul>\n</li>\n</ul>\n",
"Habitat": "<ul>\n<li>Larval red snapper swim freely within the water column.</li>\n<li>Juveniles live in shallow waters over sandy or muddy bottom habitat.</li>\n<li>Adults live on the bottom, usually near hard structures on the continental shelf that have moderate to high relief (for example, coral reefs, artificial reefs, rocks, ledges, and caves), sloping soft-bottom areas, and limestone deposits.</li>\n</ul>\n",
"Habitat Impacts": "Fishing gear used to harvest red snapper has minimal impacts on habitat.",
"Image Gallery": [
{
"src": "https://origin-east-01-drupal-fishwatch.woc.noaa.gov/sites/default/files/snapperred_1.jpg",
"alt": "Red snapper in Gray's Reef National Marine Sanctuary.",
"title": "Red snapper in Gray's Reef National Marine Sanctuary."
},
{
"src": "https://origin-east-01-drupal-fishwatch.woc.noaa.gov/sites/default/files/snapperred_2.jpg",
"alt": " Removing a red snapper otolith (ear bone). Scientists determine the age of snapper by counting annual growth rings on their otoliths, similar to counting growth rings in trees.",
"title": " Removing a red snapper otolith (ear bone). Scientists determine the age of snapper by counting annual growth rings on their otoliths, similar to counting growth rings in trees."
},
{
"src": "https://origin-east-01-drupal-fishwatch.woc.noaa.gov/sites/default/files/snapperred_3.jpg",
"alt": "A fisherman holds up his red snapper catch.",
"title": "A fisherman holds up his red snapper catch."
},
{
"src": "https://origin-east-01-drupal-fishwatch.woc.noaa.gov/sites/default/files/snapperred_4.jpg",
"alt": "Whole red snapper. Photo credit: U.S. Food and Drug Administration",
"title": "Whole red snapper. Photo credit: U.S. Food and Drug Administration"
},
{
"src": "https://origin-east-01-drupal-fishwatch.woc.noaa.gov/sites/default/files/snapperred_7.jpg",
"alt": "Red Snapper",
"title": ""
}
],
"Location": "<ul>\n<li>Red snapper are generally found at 30 to 620 feet deep in the Gulf of Mexico and along the eastern coasts of North America, Central America, and northern South America.</li>\n<li>They are rare north of the Carolinas.</li>\n</ul>\n",
"Management": null,
"NOAA Fisheries Region": "Southeast",
"Population": "Below target level in the Gulf of Mexico but fishing rate promotes population growth. Significantly below target population levels in the South Atlantic. Rebuilding plans are in place for both stocks.",
"Population Status": "<ul>\n<li>\n<p>There are two stocks of red snapper: The Gulf of Mexico stock and the South Atlantic stock. According to the most recent stock assessments:</p>\n<ul>\n<li>\n<p>The Gulf of Mexico stock is not overfished but still rebuilding to target levels (2018 stock assessment), and not subject to overfishing based on 2020 catch data. Summary stock assessment information can be found on Stock SMART.</p>\n</li>\n<li>\n<p>The South Atlantic stock is overfished and subject to overfishing (2021 stock assessment). Summary stock assessment information can be found on Stock SMART.</p>\n</li>\n</ul>\n</li>\n</ul>\n",
"Scientific Name": "Lutjanus campechanus",
"Species Aliases": "Snapper, Genuine red snapper, American reds, Spot snapper",
"Species Illustration Photo": {
"src": "https://origin-east-01-drupal-fishwatch.woc.noaa.gov/sites/default/files/red_snapper.png",
"alt": "",
"title": ""
},
"Species Name": "Red Snapper",
"Animal Health": null,
"Availability": "<p>U.S. wild-caught red snapper is available fresh year-round.</p>\n",
"Biology": "<ul>\n<li>Red snapper grow at a moderate rate, and may reach 40 inches long and 50 pounds.</li>\n<li>They can live a long time—red snapper as old as 57 years have been reported in the Gulf of Mexico and as old as 51 years in the South Atlantic.</li>\n<li>Females are able to reproduce as early as age 2.</li>\n<li>Males and females spawn from May to October, depending on their location.</li>\n<li>Red snapper feed on fish, shrimp, crab, worms, cephalopods (octopus or squid), and some plankton (tiny floating plants and animals).</li>\n<li>Young red snapper are food for the large carnivorous fish that share their habitat, such as jacks, groupers, sharks, barracudas, and morays.</li>\n<li>Large marine mammals and turtles also eat snapper.</li>\n</ul>\n",
"Bycatch": "Regulations require modified fishing gear to reduce bycatch. Release techniques improve the chance of survival of unintentionally caught fish.",
"Calories": "100",
"Carbohydrate": "0 g",
"Cholesterol": "37 mg",
"Color": "<p>The meat is pinkish with yellow tones when raw and turns somewhat lighter when cooked. Red snapper have trademark red skin and red eyes and come from domestic fisheries. To aid in identification, they are usually sold with the skin on.</p>\n",
"Disease Treatment and Prevention": null,
"Diseases in Salmon": null,
"Displayed Seafood Profile Illustration": null,
"Ecosystem Services": null,
"Environmental Considerations": null,
"Environmental Effects": null,
"Farming Methods": null,
"Farming Methods_": null,
"Fat, Total": "1.34 g",
"Feeds_": null,
"Feeds": null,
"Fiber, Total Dietary": "0 g",
"Fishing Rate": "At recommended level in the Gulf of Mexico. Reduced to end overfishing in the South Atlantic.",
"Harvest": "<ul>\n<li>Commercial sector:\n<ul>\n<li>In 2020, commercial landings of red snapper totaled approximately 7.7 million pounds and were valued at $31.5 million, according to the NOAA Fisheries commercial fishing landings database. </li>\n</ul>\n</li>\n<li>Gear types, habitat impacts, and bycatch:\n<ul>\n<li>Commercial fishermen mainly use hook-and-line gear (handlines and electric reels) to harvest red snapper, and sometimes use longlines (in the Gulf of Mexico) and spears.</li>\n<li>Commercial fishermen using hook and line gear attach multiple hooks to a vertical line and weight it at the bottom.</li>\n<li>Recreational anglers primarily use hook and line gear to harvest red snapper.</li>\n<li>Fishermen are encouraged to use venting tools and recompression devices when releasing fish suffering from barotrauma. Barotrauma occurs when the swim bladder of a fish expands as it is quickly brought to the surface. Venting tools help deflate the swim bladder and recompression devices help the fish return to the depth at which it was caught to recompress the air in the swim bladder, preventing serious injury to the fish.</li>\n<li>In the Gulf of Mexico:\n<ul>\n<li>Regulations prohibit fishing in certain areas of the Gulf of Mexico to protect sensitive fish populations and habitats.</li>\n<li>Measures are in place to reduce sea turtle bycatch by longline gear and include limiting times or areas where fishermen can fish, gear restrictions, and a limit on the number of vessels that can participate in the reef fish fishery. In addition, all commercial fishermen must follow special sea turtle release protocols and have specialized gear to improve the chances of incidentally caught sea turtles to survive.</li>\n</ul>\n</li>\n<li>In the South Atlantic:\n<ul>\n<li>Circle hooks are required when fishing for snapper and grouper species north of latitude 28° N. De-hooking devices are also required in the South Atlantic for snapper-grouper species.</li>\n<li>Measures are in place to reduce sea turtle bycatch by fishing gear and include gear restrictions and handling requirements, and a limit on the number of vessels that can participate in the snapper-grouper fishery.</li>\n</ul>\n</li>\n</ul>\n</li>\n<li>\n<p>Recreational sector:</p>\n<ul>\n<li>\n<p>Recreational anglers primarily use hook and line gear to harvest red snapper.</p>\n</li>\n<li>\n<p>In 2020, recreational anglers landed approximately 14.9 million pounds of red snapper, according to the NOAA Fisheries recreational fishing landings database. </p>\n</li>\n<li>\n<p>In the Gulf of Mexico:</p>\n<ul>\n<li>\n<p>Red snapper must be a minimum size to be caught, and there is a limit on how many red snapper anglers can keep per day.</p>\n</li>\n<li>\n<p>Charter vessels and headboats must have a permit to fish in federal waters.</p>\n</li>\n<li>\n<p>For-hire vessels must use specialized gear and follow certain sea turtle release protocols.</p>\n</li>\n</ul>\n</li>\n<li>In the South Atlantic:\n<ul>\n<li>In 2012, 2013, and 2014 the red snapper season was limited.</li>\n<li>In 2010–2011 and 2015–2016, the red snapper fishery was closed.</li>\n</ul>\n</li>\n</ul>\n</li>\n</ul>\n",
"Harvest Type": "Wild",
"Health Benefits": "<p>Red snapper is low in saturated fat and sodium and is a very good source of protein.</p>\n",
"Human_Health_": null,
"Human Health": null,
"Physical Description": "<ul>\n<li>Red snapper in deeper waters tend to be redder than those caught in shallower waters.</li>\n<li>They have a long triangular face with the upper part sloping more strongly than the lower.</li>\n<li>Their jaws are equal, with the lower one sometimes slightly projecting.</li>\n<li>They have enlarged canine teeth, which is why they are called “snappers.”</li>\n</ul>\n",
"Production": null,
"Protein": "20.51 g",
"Quote": "U.S. wild-caught red snapper is a smart seafood choice because it is sustainably managed under rebuilding plans that allow limited harvest by U.S. fishermen.",
"Quote Background Color": "#ab4946",
"Research": "<ul>\n<li>Scientists from <span>NOAA Fisheries Southeast Fisheries Science Center </span>monitor the abundance of red snapper stocks. Scientists, managers, and stakeholders assess the status of these stocks through the Southeast Data, Assessment, and Review (SEDAR) process.</li>\n<li>Using data from the Southeast Reef Fish Survey, NMFS researchers and partners recently identified the spawning season and several spawning locations for red snapper along the southeastern United States. This research is described in the open access journal PLoS ONE, and was also adapted for schools in The Science Journal for Kids.</li>\n</ul>\n",
"Saturated Fatty Acids, Total": "0.285 g",
"Selenium": "38.2 mcg",
"Serving Weight": "100 g (raw)",
"Servings": "1",
"Sodium": "64 mg",
"Source": "<p>U.S. wild-caught from North Carolina to Texas.</p>\n",
"Sugars, Total": "0 g",
"Taste": "<p>Red snapper has a sweetly mild but distinctive flavor.</p>\n",
"Texture": "<p>Red snapper is semi-firm, lean, and moist.</p>\n",
"Path": "/profiles/red-snapper",
"last_update": "02/17/2022 - 19:11"
}
I have an interface as follows which I am using to hold values returned from the payload:
interface fishDetails{
fishName?: string | null | undefined
}
const fishInfo : fishDetails = {
fishName: fishData['Species Name']
}
I then want to use fishInfo to allocate values to be used in my react functional component as follows:
return (
<div className="App">
<h1>{fishInfo.fishName}</h1>
</div>
);
It returns the following undefined error in the console:
Undefined error
undefined error
What am I doing wrong?
On the first render, fishes is [], so fishes[0] is undefined. The useEffect() then initiates your fetch request. When that resolves and calls setFishes(), React triggers a re-render in which fishes is set to response.
You should use an optional chaining operator to prevent a TypeError when attempting to access any property of fishData, which is potentially undefined as established above:
const fishInfo : fishDetails = {
fishName: fishData?.['Species Name']
}
Are there equivalents of the SEC's EDGAR (filing database) for European companies? Or any other region for that matter? For the UK I've found the "Companies House".
http://www.sedar.com/homepage_en.htm
https://www.sec.gov/edgar/searchedgar/accessing-edgar-data.htm
http://download.companieshouse.gov.uk/en_monthlyaccountsdata.html
I'm searching for (XBRL) filings outside the US, preferably for European entities.
United Kingdom: https://beta.companieshouse.gov.uk/search/companies
Ireland: www.cro.ie
France: www.infogreffe.fr
Germany: https://www.unternehmensregister.de/ureg
Italy: www.registroimprese.it
Switzerland: https://www.zefix.ch/
European Business Register (EBR): http://www.ebr.org/
GLO Filings: www.glofilings.com
So far there is no one single aggregator for EU business data.
But you can get data on the country basis.
In the UK that's Companies House - https://www.gov.uk/government/organisations/companies-house
In France, it's the Registre du commerce et des sociétés https://www.infogreffe.fr/societes/
In Germany, it's the Unternehmensregister https://www.unternehmensregister.de/ureg/?language=de&submitaction=language
For other countries there is a list on the Companies House website: https://www.gov.uk/government/pu...
I have downloaded a database cities
`Country` `City` `AccentCity` `Region` `Population` `Latitude` `Longitude`
af amir kalay Amir Kalay 16 0 34.6333 70.3333
ad aixas Aixas 06 0 42.4833 1.4667
and lot more records
I have downloaded another database called fips_10_4 to show the state of the city
country,Region,State
AD,02,"Canillo"
AD,03,"Encamp"
AD,04,"La Massana"
AD,05,"Ordino"
AD,06,"Sant Julia de Loria"
AD,07,"Andorra la Vella"
AD,08,"Escaldes-Engordany"
AE,01,"Abu Dhabi"
Now if you are thinking that Iam asking for some sql query then you are wrong.
Everything was working fine but then I came to know that the file i downloaded from
Maxmind website is incomplete as 'fips_10_4' has no record for country 'af' and region '16' .May anybody help me to deal this problem and tell me the correct place to download this complete file
FIPS 10-4 has changed. The list of changes can be found here.
In particular, AF16 (Laghman) has changed to AF35. MaxMind uses the new list.
If you need both the old and the new codes, you can find them here. You can parse the contents of the file, and replace your database table with the information found there.
AF is the two digit ISO code (IS0-3166-2) for Afghanistan, which ISO are currently trying to sell for the frankly astonishing sum of CHF 244 (Swiss Francs).
As Teleo says FIPS 10-4 has changed as detailed on the ITL website and the link Teleo has given provides the data in a more usable format. MaxMind also provides it in a better format.
I would be extremely wary about using this. Both MaxMind & Teleo's link are being provided, for free, by an external company/person that has no particular interest in keeping their data up-to-date. I notice, for instance, that the following countries are missing:
South Sudan
Sint Martaan (Dutch Part)
Bonaire, Sint Eustatius and Saba
Curaçao
The last three were part of the Netherlands Antilles, which was dissolved on 10th October 2010. Incidentally, the Netherlands Antilles, which hasn't existed for a year and a half, is still on this file.
The reason for all of this? FIPS 10-4 was withdrawn almost a decade ago on 8th September 2002. To quote the ITS website (my emphasis):
“For a replacement to FIPS 10-4, INCITS L1 is coordinating with other
standards developers and interested parties to determine whether
processing a draft proposed American National Standard or adopting an
ISO standard would be the better way forward. For more information on
the status of this activity, contact Rick Pearsall
(Richard.A.Pearsall#nga.mil).”
A quick Google brings the news the INCITS L1 is next meeting on the 12th June 2012. I wouldn't hold your breath.
Another reason not to use FIPS is that it is unlikely to be used much outside of the USA (obviously some people will still use it). While this may not matter immediately I would future proof your systems as a matter of course.
I would highly recommend using the ISO 3166 standard. It is a globally recognised way of categorising country data.
The CommonDataHub maintains a great version, which includes country and state in the same manner as FIPS 10-4. They also have other ISO states databases, which are more normalised and worth investigating.
It also maintains a list of all cities with a population greater than 5,000.
ISO maintain a copy on their website of the 3166-2 standard, which will take a bit of coding to ensure it's you're always updated at least you'll be sure it's correct. Wikipedia is also surprisingly good at keeping up-to-date. It beat CommonDataHub by a month when South Sudan was created, due to problems telling people that the data existed.
There are other places out there where this data exists, this just details what I use.
If you want to avoid databases all-together then the Yahoo! PlaceFinder API is a good place to start. It has some documented problems keeping up-to-date but at least there's a place where you can tell them they've got it wrong.
tl;dr
Don't use FIPS, it was withdrawn a decade ago. Use the globally recognised ISO standard instead.
I am not sure what is your true goal, but here is a great resource of countries and cities and all...
I want to create a database for soccer scores.
Obviously, we have:
Countries (Netherlands, Germany, (But also Europe))
Competitions (Eredivisie, Bundesliga, UEFA Europa League)
Teams (FC Twente, Bayern Munchen, Atletico Madrid)
Players (Luuk de Jong, Manuel Neuer, Tiago Mendes)
Matches (FC Twente - PSV, Bayern - Leverkusen, etc)
Events (Goal scored in 40th minute by Luuk de Jong)
I'm using Dezign in which I have created the scheme below:
Obviously, a Competition is bound to a Country, a Player to a Team, etc.
But then some problems occur. An Event belongs to a Match and a Player. So the Event could get a match_id and a player_id. But then any player of any team could 'score' in a match in which he doesn't belong (A player of team C could score in a match between team A and team B). How can I restrict this for example?
Also, a Team could compete in its 'normal' competition, but also in the Champions League. Thus, a simple competition_id in the Team entity would not suffice.
And do you suggest any other thoughts?
Edit in response to Philipp
You lack an entity to express the Lineup(team, match) along with a LineupPosition (lineup, player).
You could then associate an Event with a LineupPosition (specific player in a specific match), thereby linking your Event to the correct Match, via LineupPosition->Lineup->Match.